标签: cheerio

我可以在node.js中加载带有cheerio包的本地html文件吗?

我的硬盘上有一些html文件,我想用jquery来从中提取数据.这可以用cheerio吗?我试过给当地的路径提供cheerio,但它不起作用.我有一个想法是在节点中创建一个Web服务器,从html文件中读取,然后通过服务器将其传送给cheerio-这样吗

html jquery local node.js cheerio

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

如何使用cheerio获取脚本内容

我正在使用cheerio lib并尝试获取此脚本字段 - script type="application/json" 但由于某种原因,它无法找到这些脚本标记.怎么了?我该如何解决?

var $ = require('cheerio')
var parsedHTML = $.load(html)
console.log( parsedHTML('script').get().length ); // this is 0
Run Code Online (Sandbox Code Playgroud)

javascript node.js npm cheerio

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

BeautifulSoup喜欢为nodejs刮刀

我是前python开发人员,我已经使用BS4几年了现在我正在开发节点和是cheerio包是非常好的,但我需要像BS4一样的smth在节点中抓取

是否有一些替代cheerio?谢谢!

javascript beautifulsoup node.js web-scraping cheerio

16
推荐指数
1
解决办法
7420
查看次数

Node.js Cheerio解析器中断了UTF-8编码

我像Cheerio一样解析我的请求:

var url = http://shop.nag.ru/catalog/16939.IP-videonablyudenie-OMNY/16944.IP-kamery-OMNY-c-vario-obektivom/16704.OMNY-1000-PRO;
request.get(url, function (err, response, body) {
  console.log(body);
   $ = cheerio.load(body);
   console.log($(".description").html());
});
Run Code Online (Sandbox Code Playgroud)

作为输出,我看到内容,但在不可读的奇怪编码:

//Plain body console.log(body) (p.s. russian chars): 
<h1><span style="font-size: 16px;">??????? 3?? IP HD ?????? OMNY - ?????????? ????? ?????</span></h1><p style

//  cheerio's console.log $(".description").html()
<h1><span style="font-size: 16px;">&#x423;&#x43B;&#x438;&#x447;&#x43D;&#x430;&#x44F; 3&#x41C;&#x43F; IP HD &#x43A;&#x430;&#x43C;&#x435;&#x440;&#x430; OMNY
Run Code Online (Sandbox Code Playgroud)

目标URL链接编码采用UTF-8格式.那么为什么Cheerio会破坏我的编码呢?

试图使用iconv来编码我的身体反应:

var body1 = iconv.decode(body, "utf-8");
Run Code Online (Sandbox Code Playgroud)

console.log($(".description").html());仍然会返回奇怪的文字.

encoding node.js cheerio

13
推荐指数
1
解决办法
8691
查看次数

用Meteor.js刮刮

我可以用meteor.js刮掉吗?刚发现cheerio哪种作品非常出色request.我可以将这些用于流星,还是有类似的东西?

你有一个有效的例子吗?

node.js web-scraping meteor cheerio

12
推荐指数
1
解决办法
6554
查看次数

Cheerio:如何按文字内容选择元素?

我有一些像这样的HTML:

<span id="cod">Code:</span> <span>12345</span>
<span>Category:</span> <span>faucets</span>
Run Code Online (Sandbox Code Playgroud)

我想获取类别名称("水龙头").这是我的试用版:

var $ = cheerio.load(html.contents);
var category = $('span[innerHTML="Category:"]').next().text();
Run Code Online (Sandbox Code Playgroud)

但这不起作用(innerHTML修饰符不选择任何东西).

任何线索?

javascript jquery-selectors cheerio

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

Nodejs使用身份验证cookie进行网页抓取

最近我试图使用Nodejs,请求模块和cheerio 从网站(kicktipp)抓取信息.由于此站点需要身份验证才能查看其大部分站点,因此我尝试通过发布请求登录并检查用户是否使用以下代码登录(我使用虚拟数据替换了凭据但我在实际脚本中使用了真实数据):

var request = require('request');
var jar = request.jar();
var request = request.defaults({
  jar: jar,
  followAllRedirects: true
});
var jar = request.jar();
var cheerio = require('cheerio');

request.post({
    url: 'http://www.kicktipp.de/info/profil/loginaction',
    headers: { 'content-type': 'application/x-www-form-urlencoded' },
    method: 'post',
    jar: jar,
    body: 'kennung=test@example.com&passwort=1234567890&_charset_=UTF-8&submitbutton=Anmelden'
}, function(err, res, body){
  if(err) {
    return console.error(err);
  };

  request.get({
    url: 'http://www.kicktipp.de/',
    method: 'get',
    jar: jar
  }, function(err, res, body) {
    if(err) {
      return console.error(err);
    };

    var $ = cheerio.load(body);
    var text = $('.dropdownbox > …
Run Code Online (Sandbox Code Playgroud)

javascript cookies request node.js cheerio

11
推荐指数
1
解决办法
6812
查看次数

Cheerio Map奇怪的行为

我正在使用mapCheerio结果列表来返回属性值.我想要的是一个包含属性值列表的变量(在本例中为ID),但我得到的是ID和额外的数据.

以下代码打印ID列表:

let ids = $('[data-profileid]').map(function() {
    console.log($(this).attr('data-profileid'))
})
Run Code Online (Sandbox Code Playgroud)

结果:

1012938412
493240324
123948532
423948234
...
Run Code Online (Sandbox Code Playgroud)

但是,以下代码返回ID,但格式不同:

let ids = $('[data-profileid]').map(function() {
    return $(this).attr('data-profileid')
})

console.log(ids)
Run Code Online (Sandbox Code Playgroud)

结果:

...
'69': '234234234,
'70': '9328402397432',
'71': '1324235234',
  options:
   { withDomLvl1: true,
     normalizeWhitespace: false,
     xmlMode: false,
     decodeEntities: true },
  _root:
   { '0':
      { type: 'root',
        name: 'root',
        attribs: {},
...
Run Code Online (Sandbox Code Playgroud)

什么是这些额外的数据?当然不是必需的.我宁愿只有一个普通的数组.

node.js cheerio

10
推荐指数
2
解决办法
3258
查看次数

Async/Await with Request-Promise返回Undefined

我有两个文件; server.js和scrape.js,下面是他们目前的代码片段.

server.js:

const scrape = require("./scrape");

async function start() {
    const response = await scrape.start();
    console.log(response);
}

start();
Run Code Online (Sandbox Code Playgroud)

和scrape.js:

const cheerio = require("cheerio");
const request = require("request-promise");

go = async () => {

const options = {
  uri: "http://www.somewebsite.com/something",
  transform: function(body) {
    return cheerio.load(body);
  }
};

request(options)
  .then($ => {
    let scrapeTitleArray = [];
    $(".some-class-in-html").each(function(i, obj) {
      const data = $(this)
        .text()
        .trim();
      scrapeTitleArray.push(data);
    });
    return scrapeTitleArray;
  })
  .catch(err => {
    console.log(err);
  });
};

module.exports = {
  start: go …
Run Code Online (Sandbox Code Playgroud)

javascript asynchronous node.js async-await cheerio

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

获取TypeError:当使用cheerio和jsonframe进行抓取时,selector.includes不是一个函数

我正在尝试使用以下代码废弃网站:

const cheerio = require('cheerio');
const jsonframe = require('jsonframe-cheerio');

const $ = cheerio.load('https://coinmarketcap.com/all/views/all/');
jsonframe($); // initializes the plugin

//exception handling 
process.on('uncaughtException', err =>
  console.error('uncaught exception: ', err))
process.on('unhandledRejection', (reason, p) =>
  console.error('unhandled rejection: ', reason, p))

const frame = {
    "crypto": {         
        "selector": "tbody > tr",   
        "data": [{             
            "name": "td:nth-child(2) > a:nth-child(3)", 
            "url": {                                  
                "selector": "td:nth-child(2) > a:nth-child(3)",    
                "attr": "href"                     
            },
            "marketcap": "tr > td:nth-child(4)",
            "price": "tr > td:nth-child(5) > a:nth-child(1)", 
        }]
    }

};

let companiesList = $('tbody').scrape(frame);
console.log(companiesList); 
Run Code Online (Sandbox Code Playgroud)

但是,我 …

javascript node.js cheerio jsonframe-cheerio

9
推荐指数
2
解决办法
973
查看次数