如何使用 Scrapy 抓取多个 类 的 div
How do I scrape divs with multiple classes using Scrapy
我已在此站点上寻找答案,但没有找到适合我的答案。我正在尝试抓取 IMDB 中的热门精选页面,我想获取“a”标签的 href。
This is what the HTML of the page I'm trying to scrape looks like。我将鼠标悬停在我想要抓取的元素上。我正在使用 scrapy shell 进行测试,但我只是得到一个大小为 0 的列表。我已经尝试过:
movies = response.css('a.ipc-poster-card__title').get()
movies = response.css('div[role="group"]').getall() # to get the div first so I can work my way down to the <a> tag
movies = response.css('a.ipc-poster-card__title.ipc-poster-card__title--clamp-2.ipc-poster-card__title--clickable').get()
以及其他多行。
我尝试了最后一个,因为我在网上读到空格被 scrapy 视为层次结构,我应该使用“。”相反,对于多个 类,但是当我键入 len(movies) 时,我得到的只是大小为 0 的列表,或者我将电影作为 None对象。如何从那个“a”标签中获取 href?
正如@Joaquin 在评论中指出的那样,我现在将使用 Selenium 和 Splash。
我已在此站点上寻找答案,但没有找到适合我的答案。我正在尝试抓取 IMDB 中的热门精选页面,我想获取“a”标签的 href。 This is what the HTML of the page I'm trying to scrape looks like。我将鼠标悬停在我想要抓取的元素上。我正在使用 scrapy shell 进行测试,但我只是得到一个大小为 0 的列表。我已经尝试过:
movies = response.css('a.ipc-poster-card__title').get()
movies = response.css('div[role="group"]').getall() # to get the div first so I can work my way down to the <a> tag
movies = response.css('a.ipc-poster-card__title.ipc-poster-card__title--clamp-2.ipc-poster-card__title--clickable').get()
以及其他多行。 我尝试了最后一个,因为我在网上读到空格被 scrapy 视为层次结构,我应该使用“。”相反,对于多个 类,但是当我键入 len(movies) 时,我得到的只是大小为 0 的列表,或者我将电影作为 None对象。如何从那个“a”标签中获取 href?
正如@Joaquin 在评论中指出的那样,我现在将使用 Selenium 和 Splash。