程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Get steam preferential game data in real time with Python

編輯:Python

Catalog

Preface

Code section

development environment

First import the required modules

Request data

Get the requested data

Parsing data

Save the data

Preface

Steam By the American video game company Valve On 2003 year 9 month 12 The digital distribution platform launched on the th , It is considered to be one of the largest digital distribution platforms in the computer game industry ,Steam The platform is one of the largest comprehensive digital distribution platforms in the world . Players can buy 、 download 、 Discuss 、 Upload and share games and software .

And every week steam The meeting opened a round of special offers , You can discount the game , And players will buy the game they want

It is said that every time there is a big discount , Countless players will buy games , It can make G Fat loss death

however , For a variety of reasons , I always miss the special price of some games I want to play !!!

therefore , I was thinking. , May I use Python collect steam Data on all weekly special games

Code section development environment

Python 3.8

Pycharm

First import the required modules import randomimport timeimport requestsimport parselimport csv

Modules can pycharm Direct installation in , Input pip install XXX( Module name ) Just go

Request data url = f'https://store.steampowered.com/contenthub/querypaginated/specials/TopSellers/render/?query=&start=1&count=15&cc=TW&l=schinese&v=4&tag='headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.0.0 Safari/537.36'}response = requests.get(url=url, headers=headers) Get the requested data html_data = response.json()['results_html']print(html_data)

In this way, the source code of the web page is obtained

Parsing data selector = parsel.Selector(html_data)lis = selector.css('a.tab_item')for li in lis: href = li.css('::attr(href)').get() title = li.css('.tab_item_name::text').get() tag_list = li.css('.tab_item_top_tags .top_tag::text').getall() tag = ''.join(tag_list) price = li.css('.discount_original_price::text').get() price_1 = li.css('.tab_item_discount .discount_final_price::text').get() discount = li.css('.tab_item_discount .discount_pct::text').get() print(title, tag, price, price_1, discount, href)

Save the data

First save the data in the dictionary

dit = { ' game ': title, ' label ': tag, ' The original price ': price, ' The price is ': price_1, ' discount ': discount, ' Details page ': href,}csv_writer.writerow(dit)

Finally save it to csv in

f = open(' game _1.csv', mode='a', encoding='utf-8', newline='')csv_writer = csv.DictWriter(f, fieldnames=[ ' game ', ' label ', ' The original price ', ' The price is ', ' discount ', ' Details page ',])csv_writer.writeheader()

The final results

This is about using Python Get... In real time steam This is the end of the article on preferential game data , More about Python obtain steam Please search the previous articles of SDN or continue to browse the related articles below. I hope you can support SDN more in the future !



  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved