【问题标题】:Not able to scrape location using python无法使用 python 抓取位置
【发布时间】:2016-02-15 05:50:29
【问题描述】:

我是 python 数据抓取和尝试从 kickstarter 抓取数据的新手。 我正在使用以下代码从

中抓取位置数据

link

我正在使用以下代码

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

并出现“列表索引超出范围”错误。

我正在使用 google chrome 检查并获取上述元素的 xpath。

【问题讨论】:

  • 您试图从页面中提取哪些数据?
  • 只是也许,用 chrome,你已经连接,或者用 chrome,这个页面的结果和用 python get (User-Agent, User-Language, .... 填充浏览器,但不是你)。我尝试使用 chrome,上面的元素没有 xpath。
  • 我正在尝试提取第一个列表的位置是纽约布鲁克林,第二个列表是德国基尔,依此类推..
  • @allonhadaya...我正在尝试提取纽约布鲁克林
  • @A.H..解压纽约布鲁克林的路径是什么

标签: python web-scraping python-requests


【解决方案1】:

可以使用location-name 类选择位置元素,如下所示:

...
test_loc = test_pagetree.find_class('location-name')[0].text

【讨论】:

    猜你喜欢
    • 2018-11-17
    • 1970-01-01
    • 1970-01-01
    • 2018-09-12
    • 2015-12-14
    • 1970-01-01
    • 2023-03-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多