【发布时间】:2018-07-07 12:56:42
【问题描述】:
我正在尝试使用 python 和 BeautifulSoup4 编写一个程序,该程序查看某个游戏(在本例中为 Rust)的 Steam 市场首页,并查看每个项目并获取它们的名称和价格。到目前为止,我已经设法让这个在第一页上工作(因为每个页面只显示 10 个项目,但是当我更改第二页的网址时,我得到的输出与第一页完全相同。
我用于第一页的 URL 是:https://steamcommunity.com/market/search?appid=252490#p1_popular_desc
第二页是:https://steamcommunity.com/market/search?appid=252490#p2_popular_desc
代码是:
import bs4 as bs
import urllib.request
for web_page in range(1,3):
print('webpage number is: '+ str(web_page))
if web_page == 1:
url = "https://steamcommunity.com/market/search?appid=252490#p1_popular_desc"
print(url)
sauce = urllib.request.urlopen(url).read()
soup = bs.BeautifulSoup(sauce,'lxml')
if web_page == 2:
urlADD = '#p2_popular_desc'
url ="https://steamcommunity.com/market/search?appid=252490#p2_popular_desc"
print(url)
sauce = urllib.request.urlopen(url).read()
soup = bs.BeautifulSoup(sauce,'lxml')
for div in soup.find_all('a',class_='market_listing_row_link'):
span = div.find('span',class_='normal_price')
span2 = div.find('span',class_='market_listing_item_name')
print(span2.text)
print(span.text)
我不确定这里有什么问题,欢迎提供帮助。
【问题讨论】:
-
有人试图解决您的问题,而另一方面,您却不想回复@Matthew Cudby。但是,把它拿出来了。
-
对不起,在学校和课外活动之间,我一直在尝试你们给我的不同方式。很抱歉我很粗鲁,下次我会更及时地回复我,非常感谢我从这个社区得到的帮助
标签: python web-scraping beautifulsoup anaconda