Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript .text()和.html()在尝试使用ChereIO、nodejs对数据进行web刮取时返回空值_Javascript_Node.js_Web Scraping_Cheerio - Fatal编程技术网

Javascript .text()和.html()在尝试使用ChereIO、nodejs对数据进行web刮取时返回空值

Javascript .text()和.html()在尝试使用ChereIO、nodejs对数据进行web刮取时返回空值,javascript,node.js,web-scraping,cheerio,Javascript,Node.js,Web Scraping,Cheerio,当我尝试在控制台中使用下面的代码从web上抓取数据时,它工作正常,但如果我在加载cheerio后放置它,它将返回空值 $('div[id=“oi_sprutz_table”]>table>thead>tr>th')。text() 使用下面的代码面临问题 axios.get(url) 。然后((响应)=>{ 如果(response.status==200){ const html=response.data const$=cheerio.load(html); var标题=[]; $('div[i

当我尝试在控制台中使用下面的代码从web上抓取数据时,它工作正常,但如果我在加载cheerio后放置它,它将返回空值

$('div[id=“oi_sprutz_table”]>table>thead>tr>th')。text()

使用下面的代码面临问题

axios.get(url)
。然后((响应)=>{
如果(response.status==200){
const html=response.data
const$=cheerio.load(html);
var标题=[];
$('div[id=“oi_sprutz_table”]>table>thead>tr>th')。每个(函数(索引,元素){
headers.push($(元素).text())
});
}
});

在使用cheerio时,我是否需要以任何不同的格式指定?如果我需要任何标题,请引导我通过它。正在努力查找已加载html中的
div[id=“oi_sprutz_table”]>table>thead>tr>th
。请帮忙。提前感谢

“使用cheerio时是否需要以任何不同的格式指定?”-否您需要进行一些调试。检查
response.data
是否包含您希望它包含的内容。提供一个“返回空值”-你怎么知道?该代码中没有任何内容可以输出任何值。@Quentin-在控制台中返回值的代码块,但在y假定为b null的节点中没有。如果我错了,请纠正我。控制台上返回的只是一个承诺。