好久没更新了啊。。。最近超忙 这学期学了学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