相关疑难解决方法(0)

如何使用PhantomJS提交表格

我正在尝试使用phantomJS(这是一个很棒的工具btw!)为我有登录凭据的页面提交表单,然后将目标页面的内容输出到stdout.我能够使用幻像访问表单并成功设置其值,但我不太确定提交表单和输出后续页面内容的正确语法.到目前为止我所拥有的是:

var page = new WebPage();
var url = phantom.args[0];

page.open(url, function (status) {

  if (status !== 'success') {
      console.log('Unable to access network');
  } else {

    console.log(page.evaluate(function () {

      var arr = document.getElementsByClassName("login-form");
      var i;

      for (i=0; i < arr.length; i++) {

        if (arr[i].getAttribute('method') == "POST") {
          arr[i].elements["email"].value="mylogin@somedomain.com";
          arr[i].elements["password"].value="mypassword";

          // This part doesn't seem to work. It returns the content
          // of the current page, not the content of the page after 
          // the submit has been executed. Am I …
Run Code Online (Sandbox Code Playgroud)

javascript forms post phantomjs

161
推荐指数
4
解决办法
12万
查看次数

Phantomjs不在page.evaluate函数中执行函数

我正在使用PhantomJS节点模块(https://github.com/sgentle/phantomjs-node)抓取Facebook页面,但是当我尝试评估页面时,它不会评估我传递给它的函数.在独立脚本中执行它并使用Node解释器运行它.. Express.js应用程序中的相同代码不起作用.

这是我的代码

facebookScraper.prototype.scrapeFeed = function (url, cb) {
    f = ':scrapeFeed:';

    var evaluator = function (s) {
        var posts = [];

        for (var i = 0; i < FEED_ITEMS; i++) {
            log.info(__filename+f+' iterating step ' + i);
            log.info(__filename+f+util.inspect(document, false, null));
        }

        return {
            news: posts
        };
    }

    phantom.create(function (ph) {
        ph.createPage(function (page) {
            log.fine(__filename+f+' opening url ' + url);
            page.open(url, function (status) {
                log.fine(__filename+f+' opened site? ' + status);
                setTimeout(function() {
                    page.evaluate(evaluator, function (result) {
                        log.info(__filename+f+'Scraped feed: …
Run Code Online (Sandbox Code Playgroud)

javascript node.js phantomjs

14
推荐指数
3
解决办法
2万
查看次数

如何用phantomjs刮取链接

可以PhantomJS使用的替代BeautifulSoup

我正在尝试搜索Etsy并访问所有链接.在Python中,我知道如何做到这一点(使用BeautifulSoup)但今天我想知道我是否可以使用PhantomJS做同样的事情.我没有走得太远.

该脚本应在Etsy上搜索"hello kitty"并返回所有产品 <a class="listing-thumb" href=...></a>并在控制台中打印.理想情况下,我稍后会访问它们并获取我需要的信息.现在它只是冻结了.有任何想法吗?

var page = require('webpage').create();
var url = 'http://www.etsy.com/search?q=hello%20kitty';

page.open(url, function(status){
    // list all the a.href links in the hello kitty etsy page
    var link = page.evaluate(function() {
        return document.querySelectorAll('a.listing-thumb');
    });
    for(var i = 0; i < link.length; i++){ console.log(link[i].href); }
    phantom.exit();
});
Run Code Online (Sandbox Code Playgroud)

我玩过CasperJS玩具,可能更适合这个.

javascript beautifulsoup phantomjs casperjs

14
推荐指数
2
解决办法
3万
查看次数

PhantomJS中的评估似乎不起作用

我有JavaScript魔术的问题.当我执行此代码时:

var page = require('webpage').create();
var url="http://google.com";
page.open(url, function (status){
  if (status!== "success") {
    console.log("Fail to load: "+url)
  }else{
    console.log('1');
    page.evaluate(function() {
      console.log('2');
      });   
    console.log('3');
  }
phantom.exit();
});
Run Code Online (Sandbox Code Playgroud)

控制台只有1和3而没有2.有人可以说为什么?

如果我在我的代码DOM操作示例之后粘贴(但它永远不会执行)我有我的两个.我忘了重要的事吗?

javascript phantomjs

3
推荐指数
2
解决办法
2721
查看次数

Selenium with PhantomJS:Yahoo登录表单未提交(Python绑定)

我正在OS X上使用selenium webdriver编写一个python 2.7脚本来登录Yahoo fantasy体育并自动执行某些操作.

该脚本适用于webDriver Firefox和Chromedriver.我最近开始使用PhantomJS(GhostDriver),我发现我无法让PhantomJS Selenium Driver(GhostDriver)登录到Yahoo登录表单.

#!/usr/bin/python
import time
from selenium import webdriver
from selenium.webdriver import PhantomJS
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from sys import argv
import click

@click.command()
@click.option('--days', type=int, prompt='Number of days to set active lineup', help='Number of days to set active lineup')
@click.option('--username', prompt='Your Yahoo username:', help='Your Yahoo account username')
@click.option('--password', prompt='Your Yahoo passwordname:', help='Your Yahoo account password')
def start_active_players(days, username, …
Run Code Online (Sandbox Code Playgroud)

python selenium webdriver phantomjs ghostdriver

2
推荐指数
1
解决办法
2900
查看次数