python爬虫 爬取steam热销游戏

访客 爬虫 2023-09-01 06:58 315

好久没更新了啊。。。最近超忙 这学期学了学python 感觉很有趣 就写着玩~~~

爬取的页面是:https://store.steampowered.com/search/?filter=globaltopsellers&page=1&os=win

steam全球热销游戏榜单 一共599页

代码如下(很简单,函数都懒得写了,肯定看得懂):

import requests
from bs4 import BeautifulSoup

#根据steam网页的命名规则
i =1

while i<599:
url = "https://store.steampowered.com/search/?filter=globaltopsellers&page=" + str(i) + "&os=win"
s = requests.session()
res = s.get(url).text
soup = BeautifulSoup(res, "html.parser")
contents = soup.find().find_all('a')

for content in contents:
try:
name = content.find(class_="title").string.strip()
date = content.find("div",class_="col search_released responsive_secondrow").string.strip()
price= content.find("div",class_="col search_price responsive_secondrow").string.strip()
img_src = content.find("div",class_="col search_capsule").find('img').get("src")
href=content.get("href")
print(name,href,date,price,img_src)
except:
print("error")
i = i + 1

  

 

相关推荐

评论列表
  • 这篇文章还没有收到评论,赶紧来抢沙发吧~
关闭

用微信“扫一扫”