【问题标题】:Why is my web scraper not affected by changes in the steam URL?为什么我的网络爬虫不受 Steam URL 更改的影响?
【发布时间】:2015-06-26 21:46:34
【问题描述】:

我构建了这个网络爬虫来获取商品名称和最低价格。它可以工作,但它只会刮掉第一页(这很好,我正在努力)。但有趣的是,当我将 url http://steamcommunity.com/market/search?q= 更改为 http://steamcommunity.com/market/search?q=#p2(这是第二页项目的 url)时,我得到完全相同的输出,即第一页中的项目。任何帮助,将不胜感激。

这里是完整的代码:

import urllib2
from bs4 import BeautifulSoup

page_num = 1

url = 'http://steamcommunity.com/market/search?q='
open_url = urllib2.urlopen(url).read()
market_page = BeautifulSoup(open_url)

for i in market_page('div', {'class' : 'market_listing_row      market_recent_listing_row market_listing_searchresult'}):
    item_name = i.find_all('span', {'class' : 'market_listing_item_name'})[0].get_text()
    price = i.find_all('span')[1].get_text()
    page_num += 1
    print  item_name + ' costs ' + price

【问题讨论】:

  • 在您的代码中是 url 只是缺少 'q=' 还是您这么称呼它?
  • 哦,这不是错过,只是这篇文章的错字。

标签: python web-scraping beautifulsoup urllib2


【解决方案1】:

您应该检查页面使用 Chrome 或 Firefox 进行的 REST 调用。看起来正确的端点和参数是这样的:

http://steamcommunity.com/market/search?query=&start=10&count=10&search_descriptions=0&sort_column=quantity&sort_dir=desc

【讨论】:

  • 我将如何检查 REST 调用?
  • 如果你调出开发者工具。应该是F12。转到网络选项卡。然后刷新页面或转到一个 url,您应该会看到对服务器发出的所有请求。
猜你喜欢
  • 1970-01-01
  • 2018-08-12
  • 1970-01-01
  • 2016-12-12
  • 2014-07-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多