def remove_follow(self): # 取关店铺 unfollow_url = 'https://t.jd.com/follow/vender/unfollow.do?venderId={id}&_={time}' count = 0 while True: res = self.get( 'https://t.jd.com/follow/vender/qryCategories.do').json() if len(res['data']): for type in res['data']: for Id in type['entityIdSet']: u = unfollow_url.format(id=Id, time=Gtime()) r = self.get(u).json() if r['success']: count += 1 else: break print('已取消{}家店铺的关注'.format(count)) # 取关商品 #unfollow_good_api = 'https://follow-soa.jd.com/rpc/product/unfollow?sysName=t.jd.com&productId={skuid}' unfollow_good_api = 'https://api.m.jd.com/api?functionId=cancelFavorite&body={{"wareId":"{skuid}"}}&appid=follow_for_concert' count = 0 while True: html = self.get('https://t.jd.com/follow/product').text good_list = re.findall(r'skuid="(\d*)"', html) if good_list: for skuid in good_list: self.get(unfollow_good_api.format(skuid=skuid)).text count += 1 time.sleep(0.5) else: break print('已取消{}个商品的关注'.format(count))
def help_othres(cookie_dict): sharePin = [ 'TRJqSOe2BFV5SKL6QWxIPsAdoUJQ3Dik', '9_F8TGySa988werHZiLH4MAdoUJQ3Dik', ] headers = { 'Origin': 'https://uuj.jr.jd.com', 'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1', 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8', } ''' headers = { 'Host': 'ms.jr.jd.com', 'Accept': 'application/json', 'Origin': 'https://uuj.jr.jd.com', 'User-Agent': 'Mozilla/5.0 (Linux; Android 9; MIX 2S Build/PKQ1.180729.001; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/66.0.3359.126 MQQBrowser/6.2 TBS/044807 Mobile Safari/537.36 MMWEBID/6718 MicroMessenger/7.0.5.1440(0x27000537) Process/tools NetType/WIFI Language/zh_CN', 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8', 'Referer': 'https://uuj.jr.jd.com/wxgrowing/moneytree7/index.html?channelLV=sy&shareType=1&sharePin=9_F8TGySa988werHZiLH4MAdoUJQ3Dik&utm_source=Android*url*1562934293067&utm_medium=jrappshare&utm_term=wxfriends&from=singlemessage', 'Accept-Language': 'zh-CN,en-US;q=0.9', 'X-Requested-With': 'com.tencent.mm', } ''' for i in sharePin: data = 'reqData=%7B%22sharePin%22%3A%22{}%22%2C%22shareType%22%3A%221%22%2C%22channel%22%3A%22sy%22%2C%22source%22%3A0%2C%22riskDeviceParam%22%3A%22%7B%5C%22fp%5C%22%3A%5C%22%5C%22%2C%5C%22eid%5C%22%3A%5C%22%5C%22%2C%5C%22sdkToken%5C%22%3A%5C%22%5C%22%2C%5C%22sid%5C%22%3A%5C%22%5C%22%7D%22%7D'.format( i) response = requests.post( 'https://ms.jr.jd.com/gw/generic/uc/h5/m/login?_='.format(Gtime()), headers=headers, cookies=cookie_dict, data=data) time.sleep(1)
def filter(self, good, opt, time_limit=1000 * 60**2 * 24): ''' 设置过滤条件 flag == True为白名单模式 ''' if good.endt - Gtime() > time_limit: return False if good.money < opt.get('money', self.money_min): return False if good.count > opt.get('count', self.count_max): return False # 先用黑名单过滤一遍 for i in opt.get('deny', []): if isinstance(i, list): name = i[0] money = i[1] else: name = i money = 99999 if name in good.name and good.money < money: return False # 再用白名单过滤 for i in opt.get('allow', []): if isinstance(i, list): name = i[0] money = i[1] else: name = i money = 0 if name in good.name and good.money > money: return True # 如果时白名单模式则返回true return not opt.get('mode', True)
def get_activity_list(cookie, info=None): params = ( ('source', 'game'), ('_', Gtime()), ) response = requests.get('https://lapi.jd.com/game/energyList', headers=headers, params=params, cookies=cookie) logging.info(response.json()) return response.json()['data']
def get_user_info(cookie, info=None): params = ( ('source', 'game'), ('_', Gtime()), ) response = requests.get('https://lapi.jd.com/game/getUserTask', headers=headers, params=params, cookies=cookie) logging.info(response.json()) return response.json()['data']
def user_info(cookie_dict): data = { 'reqData': '{"shareType":1,"source":0,"riskDeviceParam":"{\\"fp\\":\\"\\",\\"eid\\":\\"\\",\\"sdkToken\\":\\"\\",\\"sid\\":\\"\\"}"}' } response = requests.post( 'https://ms.jr.jd.com/gw/generic/uc/h5/m/login?_={}'.format(Gtime()), headers=headers, data=data, cookies=cookie_dict) logging.debug("login接口响应数据{}".format(response.json())) return (response.json()['resultData']['data'])
def start_task(cookie, task_id): params = ( ('source', 'game'), ('source_id', str(task_id)), ('_', Gtime()), ) response = requests.get('https://lapi.jd.com/game/startTask', headers=headers, params=params, cookies=cookie) logging.info(response.json())
def do_active(cookie, id): params = ( ('source', 'game'), ('energy_id', str(id)), ('url', 'undefined'), ('_', Gtime()), ) response = requests.get('https://lapi.jd.com/game/doEnergyTask', headers=headers, params=params, cookies=cookie) logging.info(response.json())
def use_energy(cookie, id): params = ( ('source', 'game'), ('energy_id', id), ('_', Gtime()), ) response = requests.get('https://lapi.jd.com/game/runEnergy', headers=headers, params=params, cookies=cookie) logging.info(response.json())
def shouhuo(cookie_dict, userInfo): # 收获金果 data = { 'reqData': '{{"source":2,"sharePin":null,"userId":"{}","userToken":"{}"}}'.format( userInfo['userInfo'], userInfo['userToken']) } response = requests.post( 'https://ms.jr.jd.com/gw/generic/uc/h5/m/harvest?_={}'.format(Gtime()), headers=headers, data=data, cookies=cookie_dict) logging.info("harvest接口响应数据{}".format(response.json()))
def sell_fruit(cookie_dict): # 卖出金果 headers = { 'Origin': 'https://uuj.jr.jd.com', 'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1', 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8', } data = 'reqData={"source":2,"sharePin":null,"riskDeviceParam":""}' response = requests.post( 'https://ms.jr.jd.com/gw/generic/uc/h5/m/sell?_={}'.format(Gtime()), headers=headers, data=data, cookies=cookie_dict)
def get_rich_good(self, money_min=499, time_limit=1000 * 60**2 * 24): data = {} for name in name2cids.keys(): data[name] = [] for goods in self.get_goods_by_type(name2cids.get(name)): rich_goods = filter( lambda good: good.money >= money_min and good.endt - Gtime( ) <= time_limit and good.count <= self.count_max, goods) # 保存这些高价商品 [data[name].append(good.to_json()) for good in rich_goods] self.jd.set_new_env() print('{}类别高价已筛选完毕'.format(name)) time.sleep(3) with open('rich.json', 'w') as f: f.write(json.dumps(data))
def apply_good(id, cookie_dict): headers = { 'Referer': 'https://try.m.jd.com/activity', 'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1', } params = ( ('activityId', id), ('source', '1'), ('_s', 'm'), ('_', Gtime()), ) response = requests.get('https://try.jd.com/migrate/apply', headers=headers, params=params, cookies=cookie_dict) return response.json()
def help_othres(cookie_dict, userInfo): sharePin = [ 'TRJqSOe2BFV5SKL6QWxIPsAdoUJQ3Dik', '9_F8TGySa988werHZiLH4MAdoUJQ3Dik', ] for i in sharePin: data = 'reqData=%7B%22sharePin%22%3A%22{}%22%2C%22shareType%22%3A%221%22%2C%22channel%22%3A%22sy%22%2C%22source%22%3A0%2C%22riskDeviceParam%22%3A%22%7B%5C%22fp%5C%22%3A%5C%22%5C%22%2C%5C%22eid%5C%22%3A%5C%22%5C%22%2C%5C%22sdkToken%5C%22%3A%5C%22%5C%22%2C%5C%22sid%5C%22%3A%5C%22%5C%22%7D%22%7D'.format( i) response = requests.post( 'https://ms.jr.jd.com/gw/generic/uc/h5/m/login?_='.format(Gtime()), headers=headers, cookies=cookie_dict, data=data) time.sleep(1) logging.info("help接口响应数据{}".format(response.json()))
def valid_account(self): html = self.get(self.login_server_url.format(time=Gtime())).text #print(html) html = re.search(r'\{[\s\S]*\}', html).group(0) req = json.loads(html).get('Identity') if req.get('IsAuthenticated'): self.login = True self.nick = req.get('Unick') self.name = req.get('Name') print('{nick}登陆成功'.format(nick=self.nick)) # self.save_cookie() user = Account.select().where(Account.name == self.name).first() # print('cookie信息已使用{}天{}时{}分'.format(*Datetime2readable(user.time, time.time()))) print('京豆数量:{}'.format(self.beans)) return True else: print('登陆失败') return False
def follow_shop(self, shopid): headers = { 'Referer': 'https://item.jd.com/5129535.html', 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36', } params = ( ('callback', 'jQuery858886'), ('venderId', str(shopid)), ('sysName', 'item.jd.com'), ('_', str(Gtime())), ) #cookie = requests.utils.dict_from_cookiejar(self.session.cookies) resp = self.get('https://fts.jd.com/follow/vender/follow', headers=headers, params=params) print(resp.text)
def sign_jdjr(cookie, info=None): headers = { 'Host': 'ms.jr.jd.com', 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8', 'Origin': 'https://uf.jr.jd.com', 'Accept': 'application/json', 'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 13_1_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148/application=JDJR-App&deviceId=835406AE-A9E5-4589-9BF8-59866D34499A&clientType=ios&iosType=iphone&clientVersion=5.2.70&HiClVersion=5.2.70&isUpdate=0&osVersion=13.1.1&osName=iOS&platform=iPhone11,2&screen=812*375&src=App Store&ip=192.168.1.174&mac=02:00:00:00:00:00&netWork=1&netWorkType=1&stockSDK=stocksdk-iphone_3.2.0&sPoint=&jdPay=(*#@jdPaySDK*#@jdPayChannel=jdfinance&jdPayChannelVersion=5.2.70&jdPaySdkVersion=2.25.21.4&jdPayClientName=iOS*#@jdPaySDK*#@)', 'Referer': 'https://uf.jr.jd.com/activities/sign/v5/index.html?channel=sqtanchuang&sid=8e7dc88bfaeeff92f18232c2fcb69b5w', 'Accept-Language': 'zh-cn', } params = (('_', str(Gtime())), ) data = 'reqData=%7B%22channelSource%22%3A%22JRAPP%22%2C%22riskDeviceParam%22%3A%22%7B%5C%22deviceType%5C%22%3A%5C%22iPhone11%2C2%5C%22%2C%5C%22traceIp%5C%22%3A%5C%22%5C%22%2C%5C%22macAddress%5C%22%3A%5C%2202%3A00%3A00%3A00%3A00%3A00%5C%22%2C%5C%22imei%5C%22%3A%5C%22835406AE-A9E5-4589-9BF8-59866D34499A%5C%22%2C%5C%22os%5C%22%3A%5C%22iOS%5C%22%2C%5C%22osVersion%5C%22%3A%5C%2213.1.1%5C%22%2C%5C%22fp%5C%22%3A%5C%2214c57b0c69d0eb5bded81c693aa0012a%5C%22%2C%5C%22ip%5C%22%3A%5C%22192.168.1.174%5C%22%2C%5C%22eid%5C%22%3A%5C%22SS54IURF5FTSW753GFSKNIB4N2AGTFTLKVMGF54P2RNEW2MILXWBALJ6KK7NR47JLDLTBI5WAFOSEG3JU5GHJFL6OI%5C%22%2C%5C%22appId%5C%22%3A%5C%22com.jd.jinrong%5C%22%2C%5C%22openUUID%5C%22%3A%5C%22c6c56eae008a3a1bca1a143e9c7079bc99d30c65%5C%22%2C%5C%22uuid%5C%22%3A%5C%22%5C%22%2C%5C%22clientVersion%5C%22%3A%5C%225.2.70%5C%22%2C%5C%22resolution%5C%22%3A%5C%22812*375%5C%22%2C%5C%22channelInfo%5C%22%3A%5C%22appstore%5C%22%2C%5C%22networkType%5C%22%3A%5C%22WIFI%5C%22%2C%5C%22startNo%5C%22%3A40%2C%5C%22openid%5C%22%3A%5C%22%5C%22%2C%5C%22token%5C%22%3A%5C%22%5C%22%2C%5C%22sid%5C%22%3A%5C%22%5C%22%2C%5C%22terminalType%5C%22%3A%5C%2202%5C%22%2C%5C%22longtitude%5C%22%3A%5C%22%5C%22%2C%5C%22latitude%5C%22%3A%5C%22%5C%22%2C%5C%22securityData%5C%22%3A%5C%22%5C%22%2C%5C%22jscContent%5C%22%3A%5C%22%5C%22%2C%5C%22fnHttpHead%5C%22%3A%5C%22%5C%22%2C%5C%22receiveRequestTime%5C%22%3A%5C%22%5C%22%2C%5C%22port%5C%22%3A%5C%22%5C%22%2C%5C%22appType%5C%22%3A1%2C%5C%22optType%5C%22%3A%5C%22%5C%22%2C%5C%22idfv%5C%22%3A%5C%22%5C%22%2C%5C%22wifiSSID%5C%22%3A%5C%22%5C%22%2C%5C%22wifiMacAddress%5C%22%3A%5C%22%5C%22%2C%5C%22cellIpAddress%5C%22%3A%5C%22%5C%22%2C%5C%22wifiIpAddress%5C%22%3A%5C%22%5C%22%2C%5C%22sdkToken%5C%22%3A%5C%22WBO5IO64VANMWIXJT3OXXDYCDBVA7ZTKOUNS7EXDLXUS2OGUMFL4AHLAAFPFXDGZHMB4DOH23EA7U%5C%22%7D%22%7D' response = requests.post('https://ms.jr.jd.com/gw/generic/gry/h5/m/signIn', headers=headers, params=params, cookies=cookie, data=data) logging.info(response.json())
def double_sign(cookie, info=None): headers = { 'Host': 'nu.jr.jd.com', 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8', 'Origin': 'https://m.jr.jd.com', 'Accept': 'application/json', 'User-Agent': 'jdapp;iPhone;8.2.6;13.1.1;55d32ef767c118e0963e1e145a9b9dfb247d951a;network/wifi;ADID/D20FCC8E-56EA-4FA3-87D0-99D8AF17BCE3;supportApplePay/2;hasUPPay/0;pushNoticeIsOpen/0;model/iPhone11,2;addressid/1077100501;hasOCPay/0;appBuild/166619;supportBestPay/0;pv/90.16;apprpd/JingDou_Home;ref/https://ld.m.jd.com/userBeanHomePage/getLoginUserBean.action;psq/1;ads/;psn/55d32ef767c118e0963e1e145a9b9dfb247d951a|179;jdv/0|dmp|dmp_769|cpc|dmp_769_3059109_3C03434D7A744370ED721DB734ABF7B8_1569812439733|1569812440895|1569812443;adk/;app_device/IOS;pap/JA2015_311210|8.2.6|IOS 13.1.1;Mozilla/5.0 (iPhone; CPU iPhone OS 13_1_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148;supportJDSHWK/1', 'Referer': 'https://m.jr.jd.com/integrate/signin/index.html?channel=qjdicon&lng=108.553068&lat=34.066829&sid=4d824204a6eafcd765af12f164a76e6w&un_area=1_2901_55554_0', 'Accept-Language': 'zh-cn', } params = (('_', str(Gtime())), ) data = 'reqData=%7B%22actCode%22%3A%22FBBFEC496C%22%2C%22type%22%3A4%2C%22riskDeviceParam%22%3A%22%7B%5C%22fp%5C%22%3A%5C%22fb6ccf86676a5be04e9ef3d17c16c5e1%5C%22%2C%5C%22eid%5C%22%3A%5C%22YVZX44NXTV27MIPV4JKUNAW3CKU7BW4Z7TZ27CJ4GUCR5U2HPY2DI7NNPANJ6BRF4KMTNLAT6DMBDMYHTASJCO44OQ%5C%22%2C%5C%22sdkToken%5C%22%3A%5C%22%5C%22%2C%5C%22sid%5C%22%3A%5C%22%5C%22%7D%22%7D' response = requests.post( 'https://nu.jr.jd.com/gw/generic/jrm/h5/m/process', headers=headers, params=params, cookies=cookie, data=data) logging.info(response.json())