當前位置: 妍妍網 > 碼農

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 /免費/****