Cannot seem to scrape a div class tag in Node.js

我的未来我决定 提交于 2019-12-11 03:34:30

问题


I'm new to node.js. My experience has been in Java and VBA. I'm trying to scrape a website for a friend and all is going well until I can't get what I’m after.

<div class="gwt-Label ADC2X2-c-q ADC2X2-b-nb ADC2X2-b-Zb">Phone: +4576 102900</div>

That tag just has a text. no attr or anything. Yet I cannot scrape it using cheerio.

if(!err && resp.statusCode == 200){

    var $ = cheerio.load(body);

    var number = $('//tried everything here!').text();
    console.log(number);

this function I also played around with

    $('.ADC2X2').filter(function(i){
        console.log("Sdfs");
        console.log (i);

any suggestions would be greatly appreciated.

thanks all!


回答1:


I take answer from cheerio documentation.

$(".gwt-Label").text();

if that's not working, maybe you have many frame in page. Another possibility is page is renderer at client side, like angular pages, so element your search is not in server html, but only created after page load. If that's true, you will to use a full browser like phantomjs and not only a dom traverser tool like cheerio.



来源:https://stackoverflow.com/questions/33282011/cannot-seem-to-scrape-a-div-class-tag-in-node-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!