无法使用 python 抓取位置 [英] Not able to scrape location using python
本文介绍了无法使用 python 抓取位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是 Python 数据抓取的新手,并试图从 kickstarter 抓取数据.我正在使用以下代码从
i am newbie to python data scraping and trying to scrape data from kickstarter. i am using the following code to scrape location data from
我正在使用以下代码
test_page=requests.get('https://www.kickstarter.com/discover/advanced?term=security&sort=magic&seed=2425842&page=1')
test_pagetree= html.fromstring(test_page.content)
test_loc= test_pagetree.xpath('//[@id="projects_list"]/li/div/div/div/a/span')[0].text
并收到列表索引超出范围"错误.
and getting a 'list index out of range' error.
我正在使用谷歌浏览器检查并获取上述元素的 xpath.
I am using the google chrome to inspect and get the xpath for the element above.
推荐答案
可以使用 location-name
类来选择位置元素,如下所示:
The location elements can be selected using the location-name
class like so:
...
test_loc = test_pagetree.find_class('location-name')[0].text
这篇关于无法使用 python 抓取位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文