关于我的IGXE搬砖脚本源码
Posted miraculousb
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了关于我的IGXE搬砖脚本源码相关的知识,希望对你有一定的参考价值。
暂时只放主程序的源码。有空再整理,部分涉及账号密码的源码已处理。
# coding:utf-8 from multiprocessing import freeze_support import requests import json from datetime import datetime import re import threading import time import os import urllib3 import win32com.client from appium import webdriver as appwebdriver import itchat from selenium import webdriver from selenium.webdriver import ActionChains from selenium.webdriver.common.keys import Keys from itchat.content import * import smtplib from email.mime.text import MIMEText ‘‘‘ 购物车检测是否有1w ‘‘‘ ‘‘‘ cd D:pythonuff爬虫uff爬虫 D: pyinstaller -p D:pythonuff爬虫uff爬虫venvLibsite-packages autobuy_xiaomi8se.py ‘‘‘ def checktimeout(): global check try: appdriver.find_element_by_android_uiautomator(‘new UiSelector().resourceId("com.alipay.android.phone.safepaybase:id/key_num_dymic")‘) check = 1 except Exception as e: try: appdriver.tap([(179, 2160), (179, 2160)], 1) except: pass print(e) def aliypay(): global runtime global append global check global appdriver while 1 : try: if runtime == 150: break runtime +=1 if appdriver.find_element_by_id(‘cn.igxe:id/confirm_payment_actual_price_tv‘).text==buyprice: appdriver.tap([(949, 1104), (949, 1104)], 100) appdriver.tap([(949, 1104), (949, 1104)], 100) appdriver.tap([(567, 2200), (567, 2200)], 100) appdriver.tap([(567, 2200), (567, 2200)], 100) break else: itchat.send_msg("物品价格与加入购物车时不符",toUserName=itcaht_user_name) append = datetime.now() runtime = 150 appdriver.back() appdriver.back() appdriver.back() return except Exception as e: print(e) check = 0 time.sleep(2) #appdriver.implicitly_wait(0.2) while 1: try: if runtime == 150: break runtime+=1 appdriver.tap([(179, 2160), (179, 2160)], 1) t = threading.Thread(target=checktimeout) t.setDaemon(True) t.start() t.join(timeout=0.5) if check==0: adb2 = "adb shell input tap 179 2160" os.system(adb2) continue appdriver.tap([(875, 2060), (875, 2060)], 1) appdriver.tap([(574, 2060), (574, 2060)], 1) appdriver.tap([(875, 2060), (875, 2060)], 1) appdriver.tap([(574, 2060), (574, 2060)], 1) appdriver.tap([(875, 2060), (875, 2060)], 1) appdriver.tap([(574, 2060), (574, 2060)], 1) break except Exception as e: print(e) try: appdriver.tap([(179, 2160), (179, 2160)], 1) except: pass def wechatpay(): global runtime global append while 1 : try: if runtime == 150: break runtime +=1 appdriver.find_element_by_name(‘微信支付‘).click() appdriver.tap([(950, 1800), (950, 1800)], 100) appdriver.tap([(950, 1800), (950, 1800)], 100) break except: pass while 1 : try: if runtime == 150: break runtime +=1 if appdriver.find_element_by_id("com.tencent.mm:id/fdj").text==buyprice: appdriver.tap([(546, 725), (546, 725)], 100) appdriver.tap([(546, 725), (546, 725)], 100) time.sleep(0.3) appdriver.tap([(950, 1700), (950, 1700)], 1) appdriver.tap([(550, 1700), (550, 1700)], 1) appdriver.tap([(950, 1700), (950, 1700)], 1) appdriver.tap([(550, 1700), (550, 1700)], 1) appdriver.tap([(950, 1700), (950, 1700)], 1) appdriver.tap([(550, 1700), (550, 1700)], 1) append = datetime.now() else: append = datetime.now() itchat.send_msg("商品价格与一开始不符",toUserName=itcaht_user_name) findmainweb() break except: pass while 1: try: if runtime == 150: break runtime +=1 appdriver.find_element_by_name(‘返回商家‘).click() break except: pass def calc_count(): strday = "RUNLOG-" + time.strftime(‘%Y-%m-%d‘, time.localtime(time.time())) + ".txt" with open(strday, "r", encoding=‘utf-8‘) as log: temp = log.readlines() pattern = re.compile(‘([0-9]*?)‘) result1 = pattern.findall(str(temp)) #print(result1) i = len(result1) if i>0: res = result1[i-1].replace("(","").replace(")","") res = int(res) print(res) return res else: return 0 def judgetime(): global itemcount strtime = time.strftime(‘%H:%M:%S‘, time.localtime(time.time())) pattern = re.compile(‘00:00:‘) result1 = pattern.findall(str(strtime)) if len(result1)==1: time.sleep(60) itemcount = 0 def findmainweb(): global appdriver try: appdriver.find_element_by_id("cn.igxe:id/personalImageView") return except: pass time = 0 while 1: try: time +=1 if time == 100: try: appdriver.quit() time.sleep(2) except: pass appdriver = appwebdriver.Remote(‘http://localhost:4723/wd/hub‘, desired_caps) # 启动APP time.sleep(7) appdriver.back() try: appdriver.find_element_by_id(‘com.alipay.android.app:id/flybird_dialog_double_right_btn‘).click() #啥玩意 except: pass appdriver.find_element_by_id("cn.igxe:id/personalImageView") break except: pass def updatealiypay(): global appdriver trytime = 0 findmainweb() try: appdriver.find_element_by_name("跳过此版本").click() except: pass while 1: try: if trytime == 100: break trytime +=1 appdriver.find_element_by_id(‘cn.igxe:id/mallTextView‘) appdriver.tap([(136, 2150), (136, 2150)], 1) appdriver.tap([(136, 2150), (136, 2150)], 1) break except Exception as e: pass while 1: try: if trytime == 100: break trytime += 1 appdriver.find_element_by_xpath(‘//*[@resource-id="cn.igxe:id/goods_list_recycler"]/android.view.ViewGroup[1]‘).click() break except Exception as e: pass while 1: try: if trytime == 100: break trytime += 1 appdriver.find_element_by_xpath(‘//*[@resource-id="cn.igxe:id/sale_recyclerView"]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.widget.TextView[3]‘).click() break except Exception as e: pass while 1: try: if trytime == 100: break trytime += 1 appdriver.find_element_by_name("支付宝支付").click() break except: pass try: appdriver.find_element_by_id("cn.igxe:id/confirm_payment_commit_btn").click() except: pass if trytime == 100: try: appdriver.quit() time.sleep(2) appdriver = appwebdriver.Remote(‘http://localhost:4723/wd/hub‘, desired_caps) # 启动APP except: pass time.sleep(5) appdriver.back() appdriver.back() appdriver.back() findmainweb() cleancart() def cleancart(): appdriver.tap([(971, 2150), (971, 2150)], 1) appdriver.tap([(971, 2150), (971, 2150)], 1) appdriver.tap([(779, 2150), (779, 2150)], 1) appdriver.tap([(779, 2150), (779, 2150)], 1) runtime = 0 while 1: try: if runtime == 50: break runtime += 1 appdriver.find_element_by_name(‘管理‘).click() # 待改 break except: pass while 1: try: if runtime == 50: break runtime += 1 appdriver.find_element_by_name(‘全选‘).click() # 待改 break except: pass while 1: try: if runtime == 50: break runtime += 1 appdriver.find_element_by_id("cn.igxe:id/item_shopping_cart_commit_tv").click() break except: pass def get_screen_and_send_web(pre): screenshot = time.ctime().replace(":", "-") driver.get_screenshot_as_file("C:\Users\86131\Desktop\bugscreen\" + pre+screenshot + ".png") itchat.send_image(u"C:\Users\86131\Desktop\bugscreen/" + pre + screenshot + ".png", toUserName=itcaht_user_name) def log(printsrt): strtime = time.strftime(‘%H:%M:%S‘, time.localtime(time.time())) strday = "RUNLOG-"+time.strftime(‘%Y-%m-%d‘, time.localtime(time.time()))+".txt" print(strtime + " " + str(printsrt)) with open (strday,"a",encoding=‘utf-8‘) as log: log.write(strtime+" "+str(printsrt)+" ") def timeprint(printsrt): strtime = time.strftime(‘%H:%M:%S‘, time.localtime(time.time())) print(strtime + " " + str(printsrt)) def after_logout(): log("退出后调用") sendmsg_2() def checkbuy_info(): global appdriver global buyprice runtime_1 = 0 try: if appdriver.find_element_by_xpath(‘//*[@resource-id="cn.igxe:id/recyclerView"]/android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.widget.TextView[3]‘).text=="待买家发起报价": appdriver.tap([(562, 695), (562, 695)], 1) time.sleep(2) float1 = float(appdriver.find_element_by_xpath(‘//*[@resource-id="cn.igxe:id/unit_price_tv"]‘).text) if float1==float(buyprice): try: itchat.send_msg("价格正确,正在发送报价", toUserName=itcaht_user_name) except: pass else: try: itchat.send_msg("价格不匹配,终止交易",toUserName=itcaht_user_name) except: pass return while 1: try: if runtime_1 == 50: itchat.send_msg("发送报价失败",toUserName=itcaht_user_name) break runtime_1 += 1 appdriver.find_element_by_name(‘发送报价‘).click() time.sleep(2) appdriver.find_element_by_name(‘我已开启‘).click() break except: pass time.sleep(6) appdriver.back() time.sleep(1) appdriver.back() time.sleep(1) get_screen_and_send("BUYINFO-") if appdriver.find_element_by_xpath(‘//*[@resource-id="cn.igxe:id/recyclerView"]/android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.widget.TextView[3]‘).text == "待买家发起报价": itchat.send_msg("发送报价失败",toUserName=itcaht_user_name) else: itchat.send_msg("发送报价成功",toUserName=itcaht_user_name) except: itchat.send_msg("出现未知错误", toUserName=itcaht_user_name) get_screen_and_send("ERROR-") try: appdriver.quit() except: pass time.sleep(1) appdriver = appwebdriver.Remote(‘http://localhost:4723/wd/hub‘, desired_caps) # 启动APP time.sleep(8) def app_autobuy(): global buyprice global appdriver global buyinfo global endtime global nowtime global runtime global append runtime = 0 appnow = datetime.now() appdriver.tap([(958, 2200), (958, 2200)], 100) appdriver.tap([(958, 2200), (958, 2200)], 100) appdriver.tap([(751, 2200), (751, 2200)], 100) appdriver.tap([(751, 2200), (751, 2200)], 100) time.sleep(0.7) appdriver.tap([(125, 2039), (125, 2039)], 100) appdriver.tap([(936, 2050), (936, 2050)], 100) appdriver.tap([(936, 2050), (936, 2050)], 100) aliypay() append = datetime.now() log("购买耗时: " + str(append - appnow+endtime-nowtime) + ‘ ‘ + "runtime = " + str(runtime)) itchat.send_msg("火狐耗时:"+str(endtime-nowtime)+" "+"APP耗时:"+str(append - appnow)+" "+"购买总耗时: " + str(append - appnow+endtime-nowtime) + ‘ ‘ + "JS执行次数 = " + str(runtime)+"/150", toUserName=itcaht_user_name) get_screen_and_send("PAY-") time.sleep(2) try: appdriver.find_element_by_name(‘跳过‘).click() except: pass try: appdriver.find_element_by_name(‘我知道了‘).click() except: pass try: appdriver.find_element_by_name(‘完成‘).click() except: pass while 1: try: if runtime == 150: get_screen_and_send("BUG-") appdriver.back() appdriver.back() appdriver.back() appdriver.quit() time.sleep(2) appdriver = appwebdriver.Remote(‘http://localhost:4723/wd/hub‘, desired_caps) # 启动APP break runtime +=1 break except: pass time.sleep(8) findmainweb() try: appdriver.find_element_by_name(‘跳过此版本‘).click() except: pass temperror = 0 while 1: try: if temperror ==50: get_screen_and_send("BUG-") appdriver.back() appdriver.back() appdriver.back() appdriver.quit() time.sleep(2) appdriver = appwebdriver.Remote(‘http://localhost:4723/wd/hub‘, desired_caps) # 启动APP time.sleep(5) appdriver.tap([(958, 2056), (958, 2056)], 100) time.sleep(1) appdriver.find_element_by_xpath(‘//*[@resource-id="cn.igxe:id/personalLayout"]‘).click() break temperror+=1 appdriver.tap([(971, 2150), (971, 2150)], 1) appdriver.tap([(971, 2150), (971, 2150)], 1) time.sleep(2) appdriver.tap([(182, 1091), (182, 1091)], 1) appdriver.tap([(182, 1091), (182, 1091)], 1) break except: pass time.sleep(3) get_screen_and_send("ORDERSTATUS-") checkbuy_info() appdriver.back() if runtime == 150: itchat.send_msg("出现错误,正在尝试删除购物车货物", toUserName=itcaht_user_name) time.sleep(2) runtime = 0 findmainweb() appdriver.tap([(971, 2150), (971, 2150)], 1) appdriver.tap([(971, 2150), (971, 2150)], 1) appdriver.tap([(779, 2150), (779, 2150)], 1) appdriver.tap([(779, 2150), (779, 2150)], 1) while 1: try: if runtime == 50: break runtime += 1 appdriver.find_element_by_name(‘管理‘).click() #待改 break except: pass get_screen_and_send("PRICE-") while 1: try: if runtime == 50: break runtime += 1 appdriver.find_element_by_name(‘全选‘).click() #待改 break except: pass while 1: try: if runtime == 50: break runtime += 1 appdriver.find_element_by_id("cn.igxe:id/item_shopping_cart_commit_tv").click() break except: pass judgedel = 0 try: appdriver.find_element_by_name(‘管理‘) #待改 judgedel = 1 except: pass if (judgedel == 0): log("删除成功") itchat.send_msg("购物车货物删除成功",toUserName=itcaht_user_name) get_screen_and_send("PURCHASE-") else: log("仍然活着") itchat.send_msg("购物车货物删除失败", toUserName=itcaht_user_name) get_screen_and_send("PURCHASE-") buyinfo = 0 def get_screen_and_send(pre): try: screenshot = time.ctime().replace(":", "-") appdriver.get_screenshot_as_file( u"C:\Users\86131\Desktop\bugscreen\" + pre+screenshot + ".png") itchat.send_image(u"C:\Users\86131\Desktop\bugscreen/" +pre+ screenshot + ".png", toUserName=itcaht_user_name) except: sendmsg_2() def judge_app_online_login_and_app_front(): global appdriver global appcookies judgelogin = 0 try: appdriver.find_element_by_xpath(‘//*[@resource-id="cn.igxe:id/shoppingCartLayout"]‘).click() except: #itchat.send_msg("IGXEAPP不在前台 , 正在尝试重启",toUserName=itcaht_user_name) try: appdriver.quit() except: pass time.sleep(1) appdriver = appwebdriver.Remote(‘http://localhost:4723/wd/hub‘, desired_caps) # 启动APP time.sleep(5) #get_screen_and_send("STATE-") time.sleep(2) try: if appdriver.find_element_by_id("cn.igxe:id/sign_in_button").text == "登录": judgelogin = 1 itchat.send_msg("igxe未登录,正在尝试登录", toUserName=itcaht_user_name) appdriver.find_element_by_id("cn.igxe:id/account").clear() appdriver.find_element_by_id("cn.igxe:id/account").send_keys("******") appdriver.find_element_by_id("cn.igxe:id/password").send_keys("xxxxxxxxxxx") appdriver.hide_keyboard() time.sleep(0.5) appdriver.find_element_by_id("cn.igxe:id/sign_in_button").click() except: log("igxe已登录") time.sleep(1) try: appdriver.find_element_by_xpath(‘//*[@resource-id="cn.igxe:id/personalLayout"]‘).click() except: pass time.sleep(1) try: if judgelogin == 1: if appdriver.find_element_by_id("cn.igxe:id/userName").text=="MB秒发123": itchat.send_msg("登陆成功", toUserName=itcaht_user_name) else: itchat.send_msg("登陆失败",toUserName=itcaht_user_name) get_screen_and_send("LOGIN-") except: pass def keep_app_open(): global appdriver try: appdriver.tap([(-1, -1), (-1, -1)], 0) except Exception as e: pass def logintoigxe(): keep_app_open() global driver driver.set_page_load_timeout(3) try: driver.get(‘https://www.igxe.cn/product/730/555335‘) except: pass time.sleep(2) try: buy1 = driver.find_element_by_xpath( ‘/html/body/div[3]/div[2]/div/div/div/div[2]/div/div[2]/div[2]/div[1]/div[1]/table/tbody/tr[1]/td[7]/a[1]‘) except: pass try: buy2 = driver.find_element_by_xpath( ‘/html/body/div[3]/div[2]/div/div/div/div[2]/div/div[2]/div[2]/div[1]/div[1]/table/tbody/tr[1]/td[7]/a[2]‘) except: pass try: buy3 = driver.find_element_by_xpath( ‘/html/body/div[3]/div[2]/div/div/div/div[2]/div/div[2]/div[2]/div[1]/div[1]/table/tbody/tr[1]/td[7]/a‘) except: pass try: if buy1.text == ‘加入购物车‘: buy = buy1 except: pass try: if buy2.text == ‘加入购物车‘: buy = buy2 except: pass try: if buy3.text == ‘加入购物车‘: buy = buy3 except: pass ActionChains(driver).click(buy).perform() time.sleep(3) click = driver.find_element_by_xpath(‘/html/body/div[4]/div[1]/div/div[1]/form/ul/li[2]‘) ActionChains(driver).click(click).perform() time.sleep(1) key = driver.find_element_by_xpath(‘//*[@id="password"]‘) key.send_keys(‘xxxxxxxxxxx‘) username = driver.find_element_by_xpath(‘//*[@id="username"]‘) username.send_keys(‘******321‘) click = driver.find_element_by_xpath(‘//*[@id="login-btn"]‘) ActionChains(driver).click(click).perform() while 1: try: tses = driver.find_element_by_xpath( ‘/html/body/div[3]/div[1]/div[1]/div/div/div[2]/ul/li[7]/a[2]‘) if(tses.text==‘MB秒发123‘): break except: pass keep_app_open() def sendmsg(zhenshi,strtime,output,chajia,earnrate,jinglirun): host = ‘smtp.163.com‘ sender = ‘******321@163.com‘ pwd = ‘qq******123‘ receiver = ‘652235835@qq.com‘ body = zhenshi+strtime+‘ ‘+‘价格:‘ + output+‘ ‘ + ‘buff差价:‘ + "%.2f" % float(chajia)+‘ ‘ + ‘利率:‘ + "%.2f" % float(earnrate) + ‘%‘+‘ ‘+‘净利润:‘+"%.2f" % float(jinglirun) + ‘ ‘ msg = MIMEText(body) msg[‘subject‘] = ‘价格:‘ + output+‘ ‘ ‘净利润:‘+"%.2f" % float(jinglirun) + ‘ ‘ + zhenshi msg[‘from‘] = sender msg[‘to‘] = receiver s = smtplib.SMTP_SSL(host) s.login(sender, pwd) s.sendmail(sender, receiver, msg.as_string()) def sendmsg_2(): host = ‘smtp.163.com‘ sender = ‘******321@163.com‘ pwd = ‘qq******123‘ receiver = ‘******@qq.com‘ body = "wdnmd" msg = MIMEText(body) msg[‘subject‘] = "掉线了都" msg[‘from‘] = sender msg[‘to‘] = receiver s = smtplib.SMTP_SSL(host) s.login(sender, pwd) s.sendmail(sender, receiver, msg.as_string()) def getcookies(): keep_app_open() global cookies log(‘get new cookie‘) getcookiesdriver = webdriver.Firefox() getcookiesdriver.maximize_window() getcookiesdriver.set_page_load_timeout(3) time.sleep(1) try: getcookiesdriver.get(‘https://www.igxe.cn/product/730/555335‘) except: pass time.sleep(2) try: buy1 = getcookiesdriver.find_element_by_xpath( ‘/html/body/div[3]/div[2]/div/div/div/div[2]/div/div[2]/div[2]/div[1]/div[1]/table/tbody/tr[1]/td[7]/a[1]‘) except: pass try: buy2 = getcookiesdriver.find_element_by_xpath( ‘/html/body/div[3]/div[2]/div/div/div/div[2]/div/div[2]/div[2]/div[1]/div[1]/table/tbody/tr[1]/td[7]/a[2]‘) except: pass try: buy3 = getcookiesdriver.find_element_by_xpath( ‘/html/body/div[3]/div[2]/div/div/div/div[2]/div/div[2]/div[2]/div[1]/div[1]/table/tbody/tr[1]/td[7]/a‘) except: pass try: if buy1.text == ‘加入购物车‘: buy = buy1 except: pass try: if buy2.text == ‘加入购物车‘: buy = buy2 except: pass try: if buy3.text == ‘加入购物车‘: buy = buy3 except: pass ActionChains(getcookiesdriver).click(buy).perform() time.sleep(3) click = getcookiesdriver.find_element_by_xpath(‘/html/body/div[4]/div[1]/div/div[1]/form/ul/li[2]‘) ActionChains(getcookiesdriver).click(click).perform() time.sleep(1) key = getcookiesdriver.find_element_by_xpath(‘//*[@id="password"]‘) key.send_keys(‘xxxxxxxxxxx‘) username = getcookiesdriver.find_element_by_xpath(‘//*[@id="username"]‘) username.send_keys(‘18580890781‘) click = getcookiesdriver.find_element_by_xpath(‘//*[@id="login-btn"]‘) ActionChains(getcookiesdriver).click(click).perform() while 1: try: tses = getcookiesdriver.find_element_by_xpath( ‘/html/body/div[3]/div[1]/div[1]/div/div/div[2]/ul/li[7]/a[2]‘) if(tses.text==‘Igxe85185222‘): break except Exception as e: pass cookies = getcookiesdriver.get_cookies() time.sleep(1) getcookiesdriver.quit() keep_app_open() def judgecookie(): keep_app_open() global cookies1 headers = { ‘User-Agent‘: ‘Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Firefox/71.0.3578.98 Safari/537.36‘, } url = ‘https://www.igxe.cn/product/730/555335‘ for cookie in cookies: cookies1[cookie[‘name‘]] = cookie[‘value‘] point = requests.get(url, cookies=cookies1, headers=headers,timeout = 10) pattern = re.compile(‘.*?85185222.*?‘) result1 = pattern.findall(point.text) if result1!=[]: log("spider with cookie online") else: log("spider offline,try to get new cookie") getcookies() keep_app_open() def getbuyurl(tradeurl,hisurl,itemname): try: keep_app_open() global itemsdict global bufflowprice global k global first_url_count global getcount global count global nofound point = requests.get(hisurl,headers=header,timeout = 5,cookies=cookies1) turn = point.content.decode(encoding=‘gbk‘,errors=‘ignore‘) res = json.loads(turn) content_list = [] for i in res[‘data‘][‘items‘]: content = {} content[‘价格‘]=i[‘price‘] content_list.append(float(content[‘价格‘])) content_list.sort() if len(content_list) >= 2: pingjun = content_list[0] + content_list[1] + content_list[2] pingjun = pingjun/3 hisprice = content_list[1] if len(content_list) == 1: hisprice = content_list[0] if len(content_list) == 0: hisprice = 0 point = requests.get(tradeurl, headers=header,timeout = 5,cookies=cookies1) turn = point.content.decode(encoding=‘gbk‘, errors=‘ignore‘) res = json.loads(turn) sum=1 global url url = tradeurl url = url.replace(‘https://buff.163.com/api/market/goods/sell_order?game=csgo&goods_id=‘, ‘‘) url = url.replace(‘&page_num=1&sort_by=default&mode=&allow_tradable_cooldown=1‘, ‘‘) url = url.replace(‘ ‘, ‘‘) url = ‘https://buff.163.com/market/goods?goods_id=‘ + url + ‘&from=market#tab=selling‘ + ‘ ‘ for i in res[‘data‘][‘items‘]: content = {} content[‘价格‘]=i[‘price‘] if sum == 1: userid = i[‘user_id‘] price1 = float(content[‘价格‘]) itemsdict[itemname] = price1 itemsdict[‘price‘+itemname]=pingjun if sum == 2: price2 = float(content[‘价格‘]) chajia = price2 - price1 earnrate = chajia / itemsdict[‘price‘+itemname] earnrate *= 100 sum+=1 if sum == 3: if hisprice > 0: if earnrate > 7: if price1*1.03<pingjun: if price1*1.05<price2: getcount +=1 with open(‘buyforself.txt‘,‘a‘,encoding=‘utf-8‘) as z: log(url.replace(‘ ‘,‘‘)) log(‘价格:‘+ str(price1)+‘ 差价:‘+str(chajia)+‘ 利率:‘+str(earnrate)+‘%‘) #itchat.send_msg(itemname,toUserName=itcaht_user_name_sam) #itchat.send_msg(url.replace(‘ ‘,‘‘), toUserName=itcaht_user_name_sam) #itchat.send_msg(‘价格:‘+ str(price1)+‘ 差价:‘+str(chajia)+‘ 利率:‘+str(earnrate)+‘%‘,toUserName=itcaht_user_name_sam) z.write(url) z.write(‘价格:‘+ str(price1)+‘ 差价:‘+str(chajia)+‘ 利率:‘+str(earnrate)+‘%‘+‘ ‘) except Exception as e: pass buffcount=0 def getbuyurl_hc(tradeurl,hisurl,itemname): while 1: try: global buffcount global itemsdict global bufflowprice global k global first_url_count global getcount global count global nofound global buff_judge_exist keep_app_open() if (tradeurl in buff_judge_exist.keys()): break point = requests.get(hisurl,headers=header,timeout = 5,cookies=cookies1) turn = point.content.decode(encoding=‘gbk‘,errors=‘ignore‘) res = json.loads(turn) content_list = [] for i in res[‘data‘][‘items‘]: content = {} content[‘价格‘]=i[‘price‘] content_list.append(float(content[‘价格‘])) content_list.sort() if len(content_list) >= 2: pingjun = content_list[0] + content_list[1] + content_list[2] pingjun = pingjun/3 hisprice = content_list[1] if len(content_list) == 1: hisprice = content_list[0] if len(content_list) == 0: hisprice = 0 point = requests.get(tradeurl, headers=header,timeout = 5,cookies=cookies1) turn = point.content.decode(encoding=‘gbk‘, errors=‘ignore‘) res = json.loads(turn) sum=1 global url url = tradeurl url = url.replace(‘https://buff.163.com/api/market/goods/sell_order?game=csgo&goods_id=‘, ‘‘) url = url.replace(‘&page_num=1&sort_by=default&mode=&allow_tradable_cooldown=1‘, ‘‘) url = url.replace(‘ ‘, ‘‘) url = ‘https://buff.163.com/market/goods?goods_id=‘ + url + ‘&from=market#tab=selling‘ + ‘ ‘ for i in res[‘data‘][‘items‘]: content = {} content[‘价格‘]=i[‘price‘] if sum == 1: userid = i[‘user_id‘] price1 = float(content[‘价格‘]) itemsdict[itemname] = price1 itemsdict[‘price‘+itemname]=pingjun if sum == 2: price2 = float(content[‘价格‘]) chajia = price2 - price1 earnrate = chajia / itemsdict[‘price‘+itemname] earnrate *= 100 sum+=1 if sum == 3: if hisprice > 0: if earnrate > 7: if price1*1.03<pingjun: if price1*1.05<price2: getcount +=1 with open(‘buyforself.txt‘,‘a‘,encoding=‘utf-8‘) as z: log(url.replace(‘ ‘,‘‘)) log(‘价格:‘+ str(price1)+‘ 差价:‘+str(chajia)+‘ 利率:‘+str(earnrate)+‘%‘) #itchat.send_msg(itemname,toUserName=itcaht_user_name_sam) #itchat.send_msg(url.replace(‘ ‘,‘‘), toUserName=itcaht_user_name_sam) #itchat.send_msg(‘价格:‘+ str(price1)+‘ 差价:‘+str(chajia)+‘ 利率:‘+str(earnrate)+‘%‘,toUserName=itcaht_user_name_sam) z.write(url) z.write(‘价格:‘+ str(price1)+‘ 差价:‘+str(chajia)+‘ 利率:‘+str(earnrate)+‘%‘+‘ ‘) buff_judge_exist[tradeurl]=1 buffcount +=1 print(" "+str(buffcount)+‘/840‘,end=‘‘) break except Exception as e: pass def igxegetdict(fpoint): try: state = { "User-Agent": "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Firefox/39.0.2171.71 Safari/537.36"} sellhistoryurl = fpoint.readline() tradeurl = fpoint.readline() point = requests.get(sellhistoryurl, headers=state, timeout=5,cookies=cookies1) turn = point.content.decode(encoding=‘gbk‘, errors=‘ignore‘) js = json.loads(turn) temp = js[‘data‘] content_list = [] for i in temp: content = {} content[‘价格‘] = i[‘unit_price‘] itemname = i[‘name‘] content_list.append(float(content[‘价格‘])) content_list.sort() zhenshi = itemname.replace(‘ ‘, ‘‘) + ‘ ‘ if len(content_list) >= 2: hisprice = content_list[1] pingjun = content_list[0] + content_list[1] + content_list[2] pingjun = pingjun / 3 itemsdict[‘pingjun‘ + zhenshi] = pingjun itemsdict[‘hisprice‘ + zhenshi] = hisprice # log(‘pingjun‘+zhenshi+"已录入, 值为"+str(itemsdict[‘pingjun‘+zhenshi])) # log(‘hisprice‘+zhenshi+"已录入, 值为"+str(itemsdict[‘hisprice‘+zhenshi])) if len(content_list) == 1: hisprice = content_list[0] itemsdict[‘pingjun‘ + zhenshi] = 0 itemsdict[‘hisprice‘ + zhenshi] = hisprice if len(content_list) == 0: hisprice = 0 itemsdict[‘pingjun‘ + zhenshi] = 0 itemsdict[‘hisprice‘ + zhenshi] = hisprice first_url_count += 1 except : pass def igxegetbuyurl(tradeurl): try: global itemsdict global getcount global first_url_count global count global nofound global driver global buyprice global fbuyprice global buyinfo global driver global nowtime global endtime global nowprice global itemcount if buyinfo ==0: nowtime = datetime.now() try: driver.get(tradeurl.replace("/trade", "")) except: pass itemcount +=1 strtime = time.strftime(‘%H:%M:%S‘, time.localtime(time.time())) headers = { "User-Agent": "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Firefox/39.0.2171.71 Safari/537.36"} ret = requests.get(tradeurl, headers=headers,timeout = 3,cookies=cookies1) r = ret.content.decode(encoding=‘gbk‘,errors=‘ignore‘) res = json.loads(r) content_list = [] sum=1 price1=0.0 price2=0.0 for i in res[‘d_list‘]: content = {} content[‘价格‘] = i[‘unit_price‘] content[‘名字‘] = i[‘name‘] content[‘steamuid‘]=i[‘steam_uid‘] content_list.append(content) if sum == 1: itemname = i[‘name‘] steamuid = i[‘steam_uid‘] price1 = float(content[‘价格‘]) if sum == 2: price2 = float(content[‘价格‘]) sum+=1 if sum == 3: zhenshi = itemname.replace(‘ ‘,‘‘)+‘ ‘ if not (zhenshi in itemsdict.keys()): log(itemname+"-------------查无字典") break chajia = itemsdict[zhenshi] - price1 log("("+str(itemcount)+") "+itemname + " " + "buff价格:" + str(itemsdict[zhenshi]) + " igxe价格:" + str(price1)+" 差价:"+str(chajia)) jinglirun = chajia - (itemsdict[zhenshi]*0.035) earnrate = chajia / itemsdict[zhenshi] earnrate *= 100 if itemsdict[‘hisprice‘ + zhenshi] > 0: if price1*1.03<itemsdict[‘pingjun‘ + zhenshi]: if price1 * 1.03 < price2: if price1 * 1.03 < itemsdict[‘price‘ + zhenshi]: if earnrate > 3: #itchat.send_msg(tradeurl.replace("/trade", "")+‘价格:‘ + str(price1) + ‘ buff差价:‘ + str(chajia) + ‘ 利率:‘ + str(earnrate) + ‘%‘+‘ 净利润:‘+str(jinglirun),toUserName=itcaht_user_name_sam) #itchat.send_msg(zhenshi,toUserName=itcaht_user_name_sam) getcount += 1 log(tradeurl.replace("/trade", "")+‘价格:‘ + str(price1) + ‘ buff差价:‘ + str(chajia) + ‘ 利率:‘ + str(earnrate) + ‘%‘+‘ 净利润:‘+str(jinglirun)) if earnrate >= defearnrate and buyinfo ==1: itchat.send_msg("已经有一个自动购买在运行",toUserName=itcaht_user_name) if earnrate >= defearnrate and buyinfo ==0: buyinfo = 1 log("get real msg!") output = "%.2f" % float(price1) itchat.send_msg(zhenshi+strtime+‘ ‘+‘价格:‘ + str(output)+‘ ‘ + ‘buff差价:‘ + str(chajia)+‘ ‘ + ‘利率:‘ + str(earnrate) + ‘%‘+‘ ‘+‘净利润:‘+str(jinglirun) + ‘ ‘, toUserName=itcaht_user_name) itchat.send_msg("卖家Steam库存:"+‘ ‘+"https://steamcommunity.com/profiles/"+steamuid+"/inventory/#730", toUserName=itcaht_user_name) if price1<3500 and earnrate > 8.5 : itchat.send_msg("物品符合条件,即将自动购买", toUserName=itcaht_user_name) else: itchat.send_msg("物品不符合自动购买条件,请手动登陆进行购买", toUserName=itcaht_user_name) errortime = 0 while 1: try: errortime += 1 if errortime==1000: itchat.send_msg("火狐购买页面未能加载",toUserName=itcaht_user_name) buyinfo = 0 get_screen_and_send_web("WEB-") break getpriceelement = driver.find_element_by_xpath( ‘/html/body/div[3]/div[2]/div/div/div/div[2]/div/div[2]/div[2]/div[1]/div[1]/table/tbody/tr[1]/td[6]/span‘) strprice = "%.2f" % float(price1) eleprice = str(getpriceelement.text) eleprice = eleprice.replace("¥", ‘‘) if eleprice == strprice: buy = 0 try: buy1 = driver.find_element_by_xpath( ‘/html/body/div[3]/div[2]/div/div/div/div[2]/div/div[2]/div[2]/div[1]/div[1]/table/tbody/tr[1]/td[7]/a[1]‘) except: pass try: buy2 = driver.find_element_by_xpath( ‘/html/body/div[3]/div[2]/div/div/div/div[2]/div/div[2]/div[2]/div[1]/div[1]/table/tbody/tr[1]/td[7]/a[2]‘) except: pass try: buy3 = driver.find_element_by_xpath( ‘/html/body/div[3]/div[2]/div/div/div/div[2]/div/div[2]/div[2]/div[1]/div[1]/table/tbody/tr[1]/td[7]/a‘) except: pass try: if buy1.text == ‘加入购物车‘: buy = buy1 except: pass try: if buy2.text == ‘加入购物车‘: buy = buy2 except: pass try: if buy3.text == ‘加入购物车‘: buy = buy3 except: pass try: if buy.text != "加入购物车": itchat.send_msg("加入购物车失败",toUserName=itcaht_user_name) except: itchat.send_msg("加入购物车失败", toUserName=itcaht_user_name) ActionChains(driver).click(buy).perform() time.sleep(0.5) fbuyprice = price1 buyprice = "%.2f" % float(fbuyprice) endtime = datetime.now() app_autobuy() else: log("找不到啦") buyinfo = 0 time.sleep(2) break except Exception as e: log(e) break first_url_count += 1 except Exception as e: pass def after_logout(): log("退出后调用") sendmsg_2() def check_exsit(process_name): WMI = win32com.client.GetObject(‘winmgmts:‘) processCodeCov = WMI.ExecQuery(‘select * from Win32_Process where Name="%s"‘ % process_name) if len(processCodeCov) > 0: # 判断操作 www.iplaypy.com return 1 else: return 0 def main(): time.sleep(5) judge_app_online_login_and_app_front() judgecookie() logintoigxe() global itemcount global fbuyprice global buyprice global driver global nofound global getcount global first_url_count global sleep1 global sleep2 global count global itemsdict global appdriver global nowprice global htmlid_dict global goodsid_dict itemcount = calc_count() log(‘缓冲阶段:‘) #driver.get("https://www.bilibili.com/") #for i in range(1, 200): # driver.find_element_by_xpath(‘/html/body‘).send_keys(Keys.DOWN) #time.sleep(10) driver.set_page_load_timeout(0.5) for i in range(0,1): kk = open(‘buffdataurl‘, ‘r‘, encoding=‘utf-8‘) with open(‘buyforself.txt‘, ‘w‘, encoding=‘utf-8‘) as wtf: pass first_url_count = 1 count = 810 thread = [] for i in range(0, count): tradeurl = kk.readline() hisurl = kk.readline() itemname = kk.readline() t = threading.Thread(target=getbuyurl_hc, args=(tradeurl, hisurl, itemname,)) thread.append(t) for i in range(0, count): time.sleep(sleep1) thread[i].start() for i in range(0, count): thread[i].join() kk.close() sleep1=0.15 for i in range(0, 3): sleep2 = 0 count = 775 thread = [] ff = open(‘igxedataurl‘, ‘r‘) for i in range(0, count): t = threading.Thread(target=igxegetdict, args=(ff,)) thread.append(t) for i in range(0, count): time.sleep(sleep2) thread[i].start() for i in range(0, count): thread[i].join() ff.close() log(‘脚本开始:‘) while 1: try: judge_app_online_login_and_app_front() try: driver.set_page_load_timeout(10) driver.get(‘https://www.igxe.cn/sell/730‘) except Exception as e: print(e) log("火狐加载超时") if not check_exsit("firefox.exe"): driver = webdriver.Firefox() driver.set_page_load_timeout(10) driver.maximize_window() logintoigxe() driver.set_page_load_timeout(0.5) judgecookie() count = 775 thread = [] ff = open(‘igxedataurl‘, ‘r‘) for i in range(0, count): t = threading.Thread(target=igxegetdict, args=(ff,)) thread.append(t) for i in range(0, count): time.sleep(sleep2) thread[i].start() for i in range(0, count): thread[i].join() # log("000000000000000") ff.close() kk = open(‘buffdataurl‘, ‘r‘, encoding=‘utf-8‘) with open(‘buyforself.txt‘, ‘w‘, encoding=‘utf-8‘) as wtf: pass first_url_count = 1 count = 810 thread = [] for i in range(0,count): tradeurl = kk.readline() hisurl = kk.readline() itemname = kk.readline() t = threading.Thread(target=getbuyurl, args=(tradeurl,hisurl,itemname,)) thread.append(t) for i in range(0, count): time.sleep(sleep1) thread[i].start() for i in range(0, count): thread[i].join() kk.close() # log("111111111111111") goodsid_dict = {} htmlid_dict = {} igxe = open("igxedataurl", "r", encoding=‘utf-8‘) for i in range(0, 775): first = igxe.readline() second = igxe.readline() first = first.replace(" ", "") first = first.replace(‘https://www.igxe.cn/product/get_product_sales_history/730/‘, ‘‘) goodsid_dict[first] = 1 times = 0 igxe.close() updatealiypay() for i in range(0,35): try: driver.get(‘https://www.igxe.cn/product/730/3955‘) # except: pass appdriver.tap([(971, 2150), (971, 2150)], 1) appdriver.tap([(971, 2150), (971, 2150)], 1) appdriver.tap([(779, 2150), (779, 2150)], 1) appdriver.tap([(779, 2150), (779, 2150)], 1) findmainweb() fbuyprice = 0 nofound = 0 getcount = 0 sleep1=0.0 sleep2=0 now = datetime.now() for tmp in range(0,20): try: judgetime() times += 1 tradeurl = "https://www.igxe.cn/csgo/730?is_buying=0&is_stattrak%5B%5D=0&is_stattrak%5B%5D=0&sort=3&ctg_id=0&type_id=0&page_no=1&page_size=40&rarity_id=0&exterior_id=0&quality_id=0&capsule_id=0&_t=1566486610641" point = requests.get(tradeurl, headers=header, timeout=1) pattern = re.compile(‘"/product/730/.*?"‘) result1 = pattern.findall(point.text) sum = 0 for i in result1: goodsid = i.replace(‘"/product/730/‘, ‘‘) goodsid = goodsid.replace(‘"‘, "") if not goodsid in htmlid_dict.keys() or htmlid_dict[goodsid] == 0: htmlid_dict[goodsid] = 1 sum += 1 if goodsid in goodsid_dict.keys(): url = "https://www.igxe.cn/product/trade/730/" + goodsid igxegetbuyurl(url) if times != 1 and sum == 40: htmlid_dict = {} times = 0 tradeurl = "https://www.igxe.cn/csgo/730?is_buying=0&is_stattrak%5B%5D=0&is_stattrak%5B%5D=0&sort=3&ctg_id=0&type_id=0&page_no=2&page_size=40&rarity_id=0&exterior_id=0&quality_id=0&capsule_id=0&_t=1566559812876" point = requests.get(tradeurl, headers=header, timeout=1) pattern = re.compile(‘"/product/730/.*?"‘) result1 = pattern.findall(point.text) for i in reversed(result1): goodsid = i.replace(‘"/product/730/‘, ‘‘) goodsid = goodsid.replace(‘"‘, "") if goodsid in htmlid_dict.keys() and htmlid_dict[goodsid] == 1: htmlid_dict[goodsid] = 0 except Exception as e: timeprint(e) end = datetime.now() except: pass nowprice = 0 nowtime = 0 endtime = 0 fbuyprice = 0 buyprice = 0 nofound = 0 sleep1 = 0.25 #0.05 0.25 sleep2 = 0.0 #0.03 0.1 defearnrate = 8.5 hisprice = 0 getcount = 0 first_url_count = 0 itemsdict = {} buff_judge_exist = {} itemcount = 0 header = { ‘User-Agent‘: ‘Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Firefox/71.0.3578.98 Safari/537.36‘, } cookies = cookies = [] appcookies = [] cookies1 = {} desired_caps = { ‘platformName‘: ‘Android‘, ‘deviceName‘: ‘ea50da1f‘, ‘platformVersion‘: ‘9‘, ‘appPackage‘: ‘cn.igxe‘, ‘appActivity‘: ‘cn.igxe.ui.MainActivity‘, ‘noReset‘:‘true‘, ‘fullReset‘ : ‘false‘, ‘disableAndroidWatchers‘:‘true‘ } itchat.auto_login(hotReload=True,exitCallback=after_logout) send_userid=‘Miraculous_B‘ itcaht_user_name = itchat.search_friends(name=send_userid)[0][‘UserName‘] buyinfo = 0 driver = webdriver.Firefox() driver.maximize_window() driver.set_page_load_timeout(10) os.system(‘taskkill /f /im "adb.exe"‘) appdriver = appwebdriver.Remote(‘http://localhost:4723/wd/hub‘, desired_caps) # 启动APP appdriver.quit() appdriver = appwebdriver.Remote(‘http://localhost:4723/wd/hub‘, desired_caps) # 启动APP if __name__ == ‘__main__‘: freeze_support() main()
以上是关于关于我的IGXE搬砖脚本源码的主要内容,如果未能解决你的问题,请参考以下文章