python批量查询steam游戏价格
最近沉迷游戏的紧,看到HB有个30美元的包,心痒痒的很。于是写个小工具,查下游戏价格:
一、使用方法
首先找到HB网站,将所有游戏的名字提取下来
然后新建一个Name.txt
将游戏名粘贴进去,注意每行一个
然后运行起来,如果需要输入验证码就手动输入,运行时控制台可以看到运行日志:
如果游戏查找不到也会提示出来:
最后会自动生成详细数据的表格文件Data.csv
:
这样一下子能看到史低价格和好评率,就能决定买不买啦!
二、代码
"""
@author: Bre Athy
@contact: https://www.zhihu.com/people/you-yi-shi-de-hu-xi
@productware: PyCharm
@file: steam价格批量查询.py
@time: 2020/4/2 0:32
"""
import timefrom selenium.webdriver import Chrome,ChromeOptions
import selenium.webdriver.support.ui as ui
import selenium.webdriver.support.expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.common.exceptions import TimeoutException
import reurl = "https://steamdb.info/"
headUrl = "https://steamdb.info/search/?a=app&q="
tailUrl = "&type=1&category=0"
appUrl = "https://steamdb.info/app/"def searchGameAppidDB(appid):driver.get(appUrl+appid)try:table = ui.WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.XPATH, "//div[@class='table-responsive']")))except TimeoutException:table = Noneif table:tds = table.find_elements_by_xpath("./table/tbody/tr[@class='table-prices-current']/td")c = re.search(r"\d+", tds[1].text)if c:c_price = c.group()else:c_price = "N/A"b_price = re.search(r"\d+", tds[3].text).group()print("当前价格:",c_price)print("史低价格:",b_price)p_rate_old = driver.find_elements_by_xpath("//div[contains(@class, 'header-thing-number')]")[0].text.strip()p_rate = re.search(r".* (.*)", p_rate_old).group(1)in_game_old = driver.find_elements_by_xpath("//div[contains(@class, 'header-thing-number')]")[1].text.strip()in_game = "".join(in_game_old.split(","))print("好评率:",p_rate)print("正在游玩:",in_game)r_date = driver.find_element_by_xpath("//table[contains(@class,'table-responsive-flex')]//tr[last()]/td[last()]").text.strip()print("发行日期:",r_date)return c_price+","+b_price+","+p_rate+","+in_game+","+r_dateelse:return Falsedef searchGameNameDB(game):driver.get(headUrl+game+tailUrl)appid = Nonetry:table = ui.WebDriverWait(driver, 30).until(EC.visibility_of_element_located((By.XPATH, "//table[@id='table-sortable']")))except TimeoutException:table = Noneif table:trs = table.find_elements_by_xpath("./tbody/tr")if len(trs) == 1:appid = trs[0].find_elements_by_xpath("./td")[0].textversions = ""else:print("该游戏存在多个版本:")appids = []versions = ""for tr in trs:name = tr.find_elements_by_xpath("./td")[2].textversions += name+","print(name)if "".join(game.split()).lower() == "".join(name.split()).lower():appids.append(tr.find_elements_by_xpath("./td")[0].text)if appids:appid = appids[0]if appid:return searchGameAppidDB(appid)+","+versionselse:print("该游戏未找到相关信息")return Falseelse:print("该游戏未找到相关信息")return Falseif __name__ == "__main__":# 读取游戏名games = []file = open("Name.txt", encoding="utf-8")for line in file:games.append(line.replace("\n",""))file.close()print("本次共查询"+str(len(games))+"条项目")# 增加浏览器扩展防止爬虫检测option = ChromeOptions()option.add_experimental_option('excludeSwitches', ['enable-automation'])driver = Chrome(options=option)# 开始查询driver.get(url)print(8*"*"+" 开始查询 "+8*"*")i = 1result = "序号,游戏名,当前价格,史低价格,好评率,正在游玩,发行日期,其他版本\n"for game in games:print("-"*5,"第%d条"%i,"-"*5)print(game)str_search = searchGameNameDB(game)if str_search:result += str(i)+","+game+","+str_search+"\n"else:result += str(i)+","+game+","+"未查找到相关游戏信息"+","+headUrl+game+tailUrl+"\n"i += 1driver.close()with open("data.csv","w",encoding="utf-8-sig")as f:f.write(result)print(8 * "*" + " 查询结束 " + 8 * "*")with open("data.csv", "r", encoding="utf-8-sig")as f:content = f.read()items = content.split("\n")[1:-1]c_sum, min_sum, count, ratio = 0, 0, 0, 0for item in items:ones = item.split(",")if str.isdigit(ones[2]):c_sum += int(ones[2])min_sum += int(ones[3])ratio += float(ones[4][:-1])count += 1print("增加库存:", c_sum)print("史低入手:", min_sum)print("平均好评率", str(ratio / count)[:5] + "%")
python批量查询steam游戏价格相关推荐
- python 批量查询网页导出结果_python批量查询网页的HTTP状态码
最近业余时间在改版一个网站,改版之前频繁调整了一些栏目的属性,包括栏目的层级,这种最怕就是调整了栏目的从属关系,导致了栏目的URL地址改变,一旦改版就导致整个栏目及其下面的文章页地址变更,成为死链.而 ...
- python批量查询豆瓣书籍评分(教程附源码)
在懒人盘分享的高分电子书是利用python批量查询得到的 发现常规的豆瓣api不允许调用了,几番搜索发现一个接口 https://book.douban.com/j/subject_suggest?q ...
- 使用Python批量查询ip地址的信息
使用Python批量查询ip地址的信息 import requests from openpyxl import load_workbook from bs4 import BeautifulSoup ...
- steam插件_教程丨如何查询Steam游戏的历史价格信息
Steam商店常常会推出打折促销活动,除了游戏的本身品质和玩法外,其历史折扣信息,包括历史低价.过往打折频率,都是现在值不值得购入的参考信息. 那么如何了解一款游戏的历史价格信息呢?这里就要用到一个数 ...
- python批量查询数据库_Python + MySQL 批量查询百度收录
做SEO的同学,经常会遇到几百或几千个站点,然后对于收录情况去做分析的情况 那么多余常用的一些工具在面对几千个站点需要去做收录分析的时候,那么就显得不是很合适. 在此特意分享给大家一个批量查询百度收录 ...
- python 批量查询网页导出结果_李亚涛:python批量查询网页收录情况并计算收录率...
想要一个关键词有排名 第一件事就是保证有一个页面布局了这个关键词,而且这个页面已经被收录了. 所以,我们网站在更新一些信息的时候,比如发布资讯,如果没有被收录,那就无法获得排名,也就没办法带来流量. ...
- python在采购中应用_实例13:用Python批量查询采购物料交期及实际收货日期
我们在实例10中介绍了工程部采购物料用于新产品开发,如何从杂乱的备注栏获取工程采购单号.获取到采购单号,只是第一步,随后还需要查询物料的交期和实际收货日期. 对于负责物料跟进的员工,每个新产品开发订单 ...
- python概率游戏_来自G胖的微笑:使用python监督学习预测Steam游戏打折的概率
本期文章分为两期,第一篇我们先解决是否Steam平台的游戏会不会打折?下一期我们会详细分析影响Steam的打折因素 基本目标 使用有监督的机器学习分类模型来确定某款Steam游戏是否可以在正常一周内( ...
- python批量查询ip归属地_python3.2批量查询IP地址区域
import urllib.request #jk409 2014-7-31 by python3.4编写用于[批量]查询IP地址国家区域 def chaxun(ip_addr): ip_addr2 ...
最新文章
- Python 是一门动态的、强类型语言
- Docker的安装和使用及dockerfile简单使用
- Ubuntu 18.04 美化mac主题
- Java两种设计模式_23种设计模式(11)java策略模式
- linux cp后文件变大,使用 rsync 复制大文件的一些误解 | Linux 中国
- java必须会的linux_java程序员必须要学会的linux命令总结(推荐)
- Makefile中关于all和.PHONY
- 如何使用文件的fseek函数对文件指针进行操作
- linux机顶盒线刷教程,网络机顶盒刷机教程和详细方法,实现软件任意安装,电视免费看...
- Delphi 播放wav声音
- 教程:如何制作一个可控制的人体骨骼模型
- 用友软件计算机时间格式,如何正确设置系统日期格式?_速达软件_用友,速达,管家婆,微软,金蝶,方正,博世通,数据博士,进销存,财务软件-飞鸿软件帮助中心 -...
- weblogic安装与配置注意事项
- 数组unshift方法及重构
- iOS中block的详解weakSelf、strongSelf-转自唐巧
- Vue开发版本与生产版本的区别
- 极客假日礼物指南(我们喜欢的极客资料)
- SSM框架二手车交易网站源码+文档
- MySQL之Xtrabackup备份与恢复
- Ubuntu上安装fcitx五笔输入