【问题标题】:I want to scrape from the bottom table at this website using Horseman and PhantomJS. What should I do?我想使用 Horseman 和 PhantomJS 从这个网站的底部表格中抓取。我该怎么办?
【发布时间】:2016-12-25 21:45:36
【问题描述】:

底部表格需要滚动以显示更多数据。这是代码

【问题讨论】:

  • 如果我是你,我最好尝试直接从 Angular Scope 获取数据,而不是滚动。这会给你速度和可靠性。如果您在 Chrome DevTools 中打开页面,控制台中的以下命令会为您提供表格日期: angular.element($('.ui-grid-canvas').get(0)).scope().rowContainer.visibleRowCache
  • @a-bobkov 如何在 Node.js 中做到这一点?
  • 您正在使用的Horseman具有“评估”功能 - github.com/johntitus/node-horseman#evaluatefn-arg1-arg2
  • @a-bobkov 它返回未定义。我更新了上面的代码。

标签: node.js scroll web-scraping phantomjs node-horseman


【解决方案1】:

作为一个工作示例,下面的脚本会打印表格中的所有“Listing #”。 我希望,这会有所帮助。

var Horseman = require("node-horseman");
var horseman = new Horseman({timeout: 50000});

horseman
    .open("https://texans.seasonticketrights.com/Permanent-Seat-Licenses/For-Sale.aspx")
    .waitForSelector("div.ui-grid-cell-contents.ng-binding.ng-scope")
    .evaluate(function() {
        return angular.element($("div.ui-grid-canvas").get(0)).scope().rowContainer.visibleRowCache.map(function(listing) {return listing.entity.ListingID;}).join(',');
    })
    .then(function(listingIDs) {
        console.log(listingIDs);
    })
;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-15
    • 2020-10-23
    • 2014-03-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多