当前位置: 欣欣网 > 码农

Python 爬取Steam搜索结果

2024-04-03码农

Python,学霸

大家好!今天给你们带来了通过requests爬取Steam游戏搜索结果Python代码,仅供学习!

安装:

pip install requests

实例:

import requestsfrom bs4 import BeautifulSoupheaders = {'Accept-Language': 'zh-CN,zh;q=0.9,en'#设置中文}url = 'https://store.steampowered.com/search/?term=2077'#关键词为2077response = requests.get(url, headers=headers)soup = BeautifulSoup(response.text, 'html.parser')title_spans = soup.find_all('span', class_='title')price_divs = soup.find_all('div', class_='discount_prices')for span, price in zip(title_spans, price_divs): print(f"{span.text}\n {price.get_text(separator='/', strip=False)}\n****\n")

输出:

  • 赛博朋克 2077 ¥298.00/¥149.00****【赛博朋克 2077:往日之影】 ¥149.00/¥126.65****【赛博朋克 2077:终极版】 ¥447.00/¥253.60****Cyberpunk 2077 REDmod /免费/****Kevin(1997-2077) ¥32.00****CyberClub-2077 ¥36.00****巫师 3:狂猎 ¥149.00/¥37.25****Cyberpunk 2077 Bonus Content /免费/****DEATH STRANDING DIRECTOR'S CUT /免费/****Kevin(1997-2077) Soundtrack ¥6.00****Cyber-doge 2077: Meme runner Soundtrack ¥199.00/¥49.75****【巫师 3:狂猎 - 完全版】 ¥76.00****数字魅影: 极限竞赛 ¥38.00****American Arcadia ¥78.00****苍白花树繁茂之时Blood Flowers ¥70.00/¥28.00****纪元: 变异 /免费/****DARQ: Complete Edition /免费/****Driver Booster for Steam ¥103.00****数字魅影:序章 /免费/****Driver Booster Upgrade to Pro(Lifetime) ¥58.00/¥15.66****乱入英雄 /免费/****Night Book ¥35.00****风流霸业 ¥20.21/¥8.48****汉武大帝传-经典策略战棋 ¥70.00****子夜之章:历史的终局~MidNights of Desperado~ ¥100.00****Smart Game Booster PRO /免费/****吞食天地2022 ¥6.00****Smart Game Booster /免费/****The HeartBeat /免费/****史小坑的花前月下 ¥35.00****小怪物必须死 ¥36.00****Button Button Up! ¥22.00/¥4.40****Kingdom of Doom ¥36.00****封神榜2022 ¥32.00****Only Up: Tiny Jump ¥66.00****西游记2021 ¥11.00****纪元:变异 游戏原声集(完整版) ¥6.00****MiLE HiGH TAXi ¥66.00****玛卡巴卡 ¥6.00****A-GIRL ¥6.00****倩女幽魂2023 ¥11.00****绝境射击 ¥11.00****Lovely Defenders ¥15.00****第三区 ¥33.00****ISLAND CLASH /免费/****