码迷,mamicode.com
首页 > 编程语言 > 详细

python爬虫 爬取steam热销游戏

时间:2018-11-12 11:36:19      阅读:1984      评论:0      收藏:0      [点我收藏+]

标签:on()   strip   sea   alt   search   nbsp   ssi   psu   rip   

好久没更新了啊。。。最近超忙 这学期学了学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(id="search_result_container").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

  

 

python爬虫 爬取steam热销游戏

标签:on()   strip   sea   alt   search   nbsp   ssi   psu   rip   

原文地址:https://www.cnblogs.com/lixiaoyao123/p/9944720.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!