首先,看下其效果图如下:
采用的是selenium技术,使用了msedgedriver.exe的驱动。
下面是buffcsgo.py代码
from selenium import webdriver
from selenium.common import NoSuchElementException
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
path = "msedgedriver.exe"
service = Service(path)
browser = webdriver.Edge(service=service)
# url
url = 'https://buff.163.com/?game=csgo'
browser.get(url)
import time
time.sleep(15)
trade = browser.find_element(by=By.XPATH, value='/html/body/div[1]/div/div[2]/ul/li[2]')
trade.click()
time.sleep(2)
while True:
sell = browser.find_element(by=By.XPATH, value='//*[@id="selling"]')
sell.click()
time.sleep(0.5)
try:
for i in range(20):
i += 1
temp_price=browser.find_element(by=By.XPATH,value='//*[@id="j_list_card"]/ul/li['+str(i)+']/p/strong')
split_parts = temp_price.text.split()
temp_price=float(split_parts[1])
print(temp_price)
if temp_price<=50:
itme = browser.find_element(by=By.XPATH, value='//*[@id="j_list_card"]/ul/li['+str(i)+']/h3/a')
itme.click()
time.sleep(0.5)
price1 = browser.find_element(by=By.XPATH,value='//*[@id="market-selling-list"]/tbody/tr[2]/td[5]/div[1]/strong')
price1=float(price1.text.split()[1])
print(price1)
price2 = browser.find_element(by=By.XPATH,value='//*[@id="market-selling-list"]/tbody/tr[3]/td[5]/div[1]/strong')
price2 = float(price2.text.split()[1])
print(price2)
if price1+1<=price2:
print("可以进行购买")
name = browser.find_element(by=By.XPATH,value='//*[@id="market-selling-list"]/tbody/tr[2]/td[3]/div/div[1]/h3')
print(name.text)
# time.sleep(2)
# purchase=browser.find_element(by=By.XPATH,value='//*[@id="market-selling-list"]/tbody/tr[2]/td[6]/a')
# purchase.click()
# time.sleep(0.5)
# affirm=browser.find_element(by=By.XPATH,value='//*[@id="j_popup_epay"]/div[2]/div[4]/a')
# affirm.click()
browser.back()
time.sleep(0.5)
else:
browser.back()
time.sleep(0.5)
except NoSuchElementException:
print("无法找到元素,跳过该项")
browser.back()
time.sleep(0.5)
# 退出
# browser.quit()
有直接可运行的.exe文件,也可根据需求进行定制,对应资源可私信我分享。