选项文章从许多不同的网站抓取

Options for article scraping from many different websites

本文关键字:网站 抓取 许多不 文章 选项      更新时间:2023-09-26

我需要添加网页抓取功能到单页应用程序。

我需要从许多不同的博客和服务检索有用的内容。我所说的有用内容是指文章、文本和视频链接,以便将它们嵌入我的页面。

这个工具似乎提供了我需要的:http://www.diffbot.com/

使用它,我可以简单地输入一篇文章的URL,这个服务将检索所有的数据,我需要从单一的页面。
但是,我不需要每月处理25万个请求,这将花费每月300美元;我需要一个解决方案来处理每月约5000个请求,并有可能扩展以后。

我通过谷歌找到了很多抓取解决方案,但他们大多提供的解决方案是从少数网站定期抓取自定义内容-这不是我需要的。另外,我在这方面没有经验,所以我希望你能告诉我应该用什么来达到这个目的。我主要处理JavaScript。

另外,是否有可能允许页面被客户端的浏览器抓取,而不是服务器端?

我用ReactJS和Flux架构开发SPA。服务器NodeJS+Express,数据库- Backendless

这听起来像一个自定义的解决方案,也许建立在node.js将是你最好的选择(考虑到js的要求)。您可以使用几个节点模块来完成此任务。我的建议如下:

request -用于从目标网页

获取html

cheerio -用于过滤从请求

收集的html

node-horseman -用于在目标网页上执行javascript(用于更高级的抓取)

artoo -客户端抓取库(我从未使用过这个,但它可能是你正在寻找的)

关于SPA的开发,我推荐sailsjs。

下面是一个使用上述模块抓取https://rotogrinders.com/pages/mlb-pitcher-hub-sp-salary-charts-260515的示例节点应用程序

请求,恭喜恭喜:

var cheerio = require('cheerio'),
    request = require('request');
//Define your target URL and HTTP method here
var options = {
  url: 'https://rotogrinders.com/pages/mlb-pitcher-hub-sp-salary-charts-260515',
  method: 'GET'
}
// Use request to grab the HTML defined in options and return the contents in "body"
request(options, function (err, res, body) {
  if (!err && res.statusCode == 200) {
    // Load the "body" with cheerio
    var $ = cheerio.load(body);
    // grab each occurrence of the matched html (Use Chrome developer tools to determine CSS) using Cheerio
    $('tbody').children().each(function(i, element){
      var $element = $(element);
      var name = $element.children().eq(0).text().trim();
      var salary = $element.children().eq(3).text().trim();
      // Put the filtered data in an object
      var post = {
        name: name,
        salary: salary
      }
      // Print the object to the console
      console.log(post);
    });
  }
});