91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

資源簡介

# JD_AutoBuy ## 京東搶購 Python爬蟲,自動登錄京東網(wǎng)站,查詢商品庫存,價格,顯示購物車詳情等。 可以指定搶購商品,自動購買下單,然后手動去京東付款就行。 ## chang log + 2017-03-30 實現(xiàn)二維碼掃碼登陸 ## 運行環(huán)境 Python 2.7 ## 第三方庫 - [Requests][1]: 簡單好用,功能強大的Http請求庫 - [beautifulsoup4][2]: HTML文檔格式化及便簽選擇器 ## 環(huán)境配置 ``` Python pip install requests pip install beautifulsoup4 ``` ## 使用幫助 ``` cmd > python scraper-jd.py -h usage: scraper-jd.py [-h] [-u USERNAME] [-p PASSWORD] [-g GOOD] [-c COUNT] [-w WAIT] [-f] [-s] Simulate to login Jing Dong, and buy sepecified good optional arguments: -h, --help show this help message and exit -u USERNAME, --username USERNAME Jing Dong login user name -p PASSWORD, --password PASSWORD Jing Dong login user password -g GOOD, --good GOOD Jing Dong good ID -c COUNT, --count COUNT The count to buy -w WAIT, --wait WAIT Flush time interval, unit MS -f, --flush Continue flash if good out of stock -s, --submit Submit the order to Jing Dong ``` ## 實例輸出 ``` cmd +++++++++++++++++++++++++++++++++++++++++++++++++++++++ Thu Mar 30 17:10:01 2017 > 請打開京東手機客戶端,準備掃碼登陸: 201 : 二維碼未掃描 ,請掃描二維碼 201 : 二維碼未掃描 ,請掃描二維碼 201 : 二維碼未掃描 ,請掃描二維碼 201 : 二維碼未掃描 ,請掃描二維碼 202 : 請手機客戶端確認登錄 200 : BADACIFYhf6fakfHvjiYTlwGzSp4EjFATN3Xw1ePR1hITtw0 登陸成功 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ Thu Mar 30 17:10:28 2017 > 商品詳情 編號:3133857 庫存:現(xiàn)貨 價格:6399.00 名稱:Apple iPhone 7 Plus (A1661) 128G 黑色 移動聯(lián)通電信4G手機 鏈接:http://cart.jd.com/gate.action?pid=3133857&pcount=1&ptype=1 商品已成功加入購物車! 購買數(shù)量:3133857 > 1 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ Thu Mar 30 17:10:30 2017 > 購物車明細 購買 數(shù)量 價格 總價 商品 Y 1 6399.00 6399.00 Apple iPhone 7 Plus (A1661) 128G 黑色 移動聯(lián)通電信4G手機 總數(shù): 1 總額: 6399.00 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ Thu Mar 30 17:10:30 2017 > 訂單詳情 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ ... ``` ## 注 代碼僅供學習之用,京東網(wǎng)頁不斷變化,代

資源截圖

代碼片段和文件信息

#?-*-?coding:?utf-8?-*-

“““
JD?online?shopping?helper?tool
-----------------------------------------------------

only?support?to?login?by?QR?code?
username?/?password?is?not?working?now.

“““


import?bs4
import?requests
import?requests.packages.urllib3
requests.packages.urllib3.disable_warnings()

import?os
import?time
import?json
import?random


import?argparse
#from?selenium?import?webdriver


import?sys
reload(sys)
sys.setdefaultencoding(‘utf-8‘)

#?get?function?name
FuncName?=?lambda?n=0:?sys._getframe(n?+?1).f_code.co_name


def?tags_val(tag?key=‘‘?index=0):
‘‘‘
return?html?tag?list?attribute?@key?@index
if?@key?is?empty?return?tag?content
‘‘‘
if?len(tag)?==?0?or?len(tag)?<=?index:
return?‘‘
elif?key:
txt?=?tag[index].get(key)
return?txt.strip(‘?\t\r\n‘)?if?txt?else?‘‘
else:
txt?=?tag[index].text
return?txt.strip(‘?\t\r\n‘)?if?txt?else?‘‘


def?tag_val(tag?key=‘‘):
‘‘‘
return?html?tag?attribute?@key
if?@key?is?empty?return?tag?content
‘‘‘
if?tag?is?None:?
return?‘‘
elif?key:
txt?=?tag.get(key)
return?txt.strip(‘?\t\r\n‘)?if?txt?else?‘‘
else:
txt?=?tag.text
return?txt.strip(‘?\t\r\n‘)?if?txt?else?‘‘


class?JDWrapper(object):
‘‘‘
This?class?used?to?simulate?login?JD
‘‘‘

def?__init__(self?usr_name=None?usr_pwd=None):
#?cookie?info
self.trackid?=?‘‘
self.uuid?=?‘‘
self.eid?=?‘‘
self.fp?=?‘‘

self.usr_name?=?usr_name
self.usr_pwd?=?usr_pwd

self.interval?=?0

#?init?url?related
self.home?=?‘https://passport.jd.com/new/login.aspx‘
self.login?=?‘https://passport.jd.com/uc/loginService‘
self.imag?=?‘https://authcode.jd.com/verify/image‘
self.auth?=?‘https://passport.jd.com/uc/showAuthCode‘

self.sess?=?requests.Session()

self.headers?=?{
‘User-Agent‘?:?‘Mozilla/5.0?(Windows?NT?10.0;?WOW64)?AppleWebKit/537.36?(KHTML?like?Gecko)?Chrome/51.0.2704.103?Safari/537.36‘
‘ContentType‘:?‘text/html;?charset=utf-8‘
‘Accept-Encoding‘:‘gzip?deflate?sdch‘
???????? ‘Accept-Language‘:‘zh-CNzh;q=0.8‘
‘Connection‘?:?‘keep-alive‘
}

self.cookies?=?{

}

‘‘‘
try:
self.browser?=?webdriver.PhantomJS(‘phantomjs.exe‘)
except?Exception?e:
print?‘Phantomjs?initialize?failed?:‘?e
exit(1)
‘‘‘

@staticmethod
def?print_json(resp_text):
‘‘‘
format?the?response?content
‘‘‘
if?resp_text[0]?==?‘(‘:
resp_text?=?resp_text[1:-1]

for?kv?in?json.loads(resp_text).items():
print?u‘%s?:?%s‘?%?(k?v)

@staticmethod
def?response_status(resp):
if?resp.status_code?!=?requests.codes.OK:
print?‘Status:?%u?Url:?%s‘?%?(resp.status_code?resp.url)
return?False
return?True

def?_need_auth_code(self?usr_name):
#?check?if?need?auth?code
#?
auth_dat?=?{
‘loginName‘:?usr_name
}
payload?=?{
‘r‘?:?random.random()
‘version‘?:?2015
}

resp?=?self.sess.post(self.auth?data=auth_dat?params=payload)
if?self.response_status(resp)?:?
js?=?json.loads(resp.text[1:-1])
return?js[‘verifycode‘]

print?u‘獲取是否需要驗證碼

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2017-11-24?16:12??jd-autobuy-master\
?????文件????????2851??2017-11-24?16:12??jd-autobuy-master\README.md
?????文件???????20021??2017-11-24?16:12??jd-autobuy-master\scraper-jd.py

評論

共有 條評論