joh*_*y 5 1 javascript jquery web-scraping
我正在编写一个刮刀,作为我在IMDB上进行的测试并尝试从列表中获取一些演员名称,这是该页面的链接.
当我在控制台中调用此函数时,我正试图从html中取出名称
$('.list_item').find('.info a:eq(0)').each(function (){ console.log(this)})
Run Code Online (Sandbox Code Playgroud)
控制台将记录标签中的所有内容,但是当我尝试抓取html时,我得到一个错误,undefined不是一个函数.
$('.list_item').find('.info a:eq(0)').each(function (){ console.log(this.html())})
Run Code Online (Sandbox Code Playgroud)
但是,如果我给他们的标签一个id我可以抓住它
$('#testname').html();
Run Code Online (Sandbox Code Playgroud)
这样可以获得正确的名称
更改
console.log(this.html());
Run Code Online (Sandbox Code Playgroud)
至
console.log($(this).html());
Run Code Online (Sandbox Code Playgroud)
该方法.html()需要一个jQuery对象.你需要包装this- > $(this).