最近沉迷游戏的紧,看到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 time
from 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 re
url = "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 = None
if 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[