标签: cheerio

如何使用node.js在cheerio中获取元素名称

如何在cheerio中获取元素的名称?

相当于jQuery,.attr('name')但是undefined在cheerio 中返回.

html node.js web-scraping cheerio

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

使用 Node.js 抓取 JavaScript 生成的网站

当我解析静态 html 页面时,我的 node.js 应用程序运行良好。但是,当 URL 是 JavaScript 生成的页面时,该应用程序将无法运行。如何抓取 JavaScript 生成的网页?

我的应用程序.js

var express = require('express'),
  fs = require('fs'),
  request = require('request'),
  cheerio = require('cheerio'),
  app = express();

app.get('/scrape', function( req, res ) {

  url = 'http://www.apache.org/';

  request( url, function( error, response, html ) {
    if( !error ) {
      var $ = cheerio.load(html);

      var title, release, rating;
      var json = { title : "" };

      $('body').filter(function() {
        var data = $(this);
        title = data.find('.panel-title').text();
        json.title = title;
      })
    }

    fs.writeFile('output.json', …
Run Code Online (Sandbox Code Playgroud)

javascript node.js web-scraping express cheerio

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

用cheerio刮文本

我想只是凑Jung Ho Kang5,从这个网站,并把它变成一个对象.我想排除(R)和中的所有内容SS.

<td id="lineup-table-top">
  <b class="text-muted pad-left-10">5</b>
  &nbsp;&nbsp;&nbsp;Jung Ho Kang 
  <small class="text-muted">(R)</small> 
  <small class="text-muted">SS</small>
</td>
Run Code Online (Sandbox Code Playgroud)

这是我的代码:

var someObjArr = [];

$('td#lineup-table-top').each(function(i, element){

    //Get the text from cheerio.
    var text = $(this).text();

    //if undefined, create the object inside of our array.
    if(someObjArr[i] == undefined){

        someObjArr[i] = {};
    };

    //Update the salary property of our object with the text value.
    someObjArr[i].name = text;

    $('b.pad-left-10').each(function(i, element){

        //Get the text from cheerio.
        var text = …
Run Code Online (Sandbox Code Playgroud)

javascript node.js cheerio

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

使用 cherrio 选择器获取评论元素文本

这个类似于 jQuery 的选择器“cheerio”尝试从 html 页面中的注释节点获取注释。
$ 是cheerio 对象。它怎么能做到呢?谢谢

console.log($('*').contents().length); //reports back more than 1000


$('*').contents().filter(function() {
  if (this.nodeType == 8) {

    //the following gives null for every node found
    console.log($(this).html());

    //the following gives blank for every node found
    console.log($(this).text());
  }
});
Run Code Online (Sandbox Code Playgroud)

jquery cheerio

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

Cheerio 如何忽略某个标签的元素

我正在抓取网页的正文:

axios.get(url)
.then(function(response){
        var $ = cheerio.load(response.data);
        var body = $('body').text();
    });
Run Code Online (Sandbox Code Playgroud)

问题是,我想从<footer>标签中排除内容。我怎么做?

node.js cheerio

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

Cheerio 从选择类中获取选项值

我正在尝试从选择类中的选项列表中获取所有值:

<select class="list_items">
  <option value="1">1</option>
  <option value="2">2</option>
  <option value="3">3</option>
  <option value="4">4</option>
</select>
Run Code Online (Sandbox Code Playgroud)

我怎样才能在cheerio实现这一目标?

node.js cheerio

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

Web 从交互式网络地图中抓取屏幕图像

我需要将地图组件提取到静态图像: http://www.bom.gov.au/water/landscape/#/sm/Relative/day/-35.30/145.17/5/Point////2018 /12/16/

此页面包含基于 Leaflet 的交互式网络地图,其中图层数据每天通过网络地图服务更新。提取的图像应包含地图上加载的任何图层。

这也需要自动化,这样就没有人会打开网络浏览器并访问该 URL。提取的图像将转到 Word 文档。

我是一名Python和nodejs程序员,但我无法通过BeautifulSoup for Python或Cheerio for nodejs进行网页抓取来实现它,因为地图不是img元素而是一些动态DIV。如何将地图组件作为图像?

python beautifulsoup node.js web-scraping cheerio

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

Cheerio:如何通过数据标签选择

假设我有一个这样的元素:

<div data-testid="counter">Count: 3</div>
Run Code Online (Sandbox Code Playgroud)

如何通过查询 来选择该元素"counter" data-testid

cheerio

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

如何在cheerio中获得div的孩子

我正在与cheerio合作,但我被困在我想获得<div class="card">.

<div class="Card">  
   <div class="title">
    <a target="_blank" href="test">
        Php </a>
    </div>
    <div>some content</div>
    <div>some content</div>
    <div>some content</div>
 </div>
Run Code Online (Sandbox Code Playgroud)

我正确地获得了第一个 childern,但我想获得div class=titlechildern a href 值。我是 node 的新手,我已经在搜索它,但没有得到合适的答案。

var jobs = $("div.jobsearch-SerpJobCard",html);

这是我的脚本

 const rp = require('request-promise');
 const $  = require('cheerio');
 const potusParse = require('./potusParser');
 const url = "";

 rp(url)
   .then((html)=>{
     const Urls = [];
      var jobs = $("div.Card",html);


      for (let i = 2; i < jobs.length; i++) {
         Urls.push(
                $("div.Card  > div[class='title'] >a", html)[i].attribs.href
     );
   } …
Run Code Online (Sandbox Code Playgroud)

javascript arrays node.js cheerio

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

为什么cheerio.load() 函数不能正常工作

const cheerio = require('cheerio');

const HTML = `<tbody>
<tr>
    <th>
        Team Name
    </th>
    <th>
        Year
    </th>
    <th>
        Wins
    </th>
    <th>
        Losses
    </th>
</tr>
</tbody>
`;

const $ = cheerio.load(HTML);
const text = $('tr').text();
console.log(text);
Run Code Online (Sandbox Code Playgroud)

在这里我没有收到文本。为什么??HTML 字符串中是否有任何错误?我无法确定问题。请帮忙!!!

javascript node.js web-scraping cheerio

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