【发布时间】:2014-05-31 16:30:51
【问题描述】:
我正在使用Node.js 和cheerio 进行网页抓取,目前我无法提取img 标签的绝对网址。
代码如下:
$('.images').each(function () {
console.log("absolute url: " , $(this)[0].src)
});
我正在返回 undefined 以获取在 Node.js 中运行该代码的 src 值,但是当我直接在 Chrome 控制台中应用该代码时,工作正常。似乎 Node.js 没有实现 src财产 ?接下来我尝试输出$(this)[0]的属性
{
"type": "tag",
"name": "img",
"attribs": {
"class": "images",
"src": "/gfx/image.png",
"alt": "",
"children": [],
"next": {
"data": "\r\n ",
"type": "text",
"next": null,
"prev": "[Circular]",
"parent": {}
}
}
}
真的,它没有src,只有attrbs.src 返回相对网址,有什么想法吗?
【问题讨论】: