-
大小: 5KB文件类型: .zip金币: 2下载: 1 次发布日期: 2021-06-17
- 语言: Python
- 标签:
资源简介
Python爬虫,京东自动打码登录,指定商品自动加购物车,自动下单,指定时间抢购商品
代码片段和文件信息
import requests
import random
import json
import os
import time
import re
from lxml import etree
from rk import *
url = ‘https://passport.jd.com/new/login.aspx‘
headers = {
‘User-Agent‘:‘Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_2) AppleWebKit/537.36 (KHTML like Gecko) Chrome/55.0.2883.95 Safari/537.36‘
‘ContentType‘: ‘text/html; charset=utf-8‘
‘Accept-Encoding‘:‘gzip deflate sdch‘
‘Accept-Language‘:‘zh-CNzh;q=0.8‘
‘Connection‘ : ‘keep-alive‘
}
s = requests.Session()
s.headers = headers
# 请求登录页面
req1 = s.get(url=url headers=headers)
sel = etree.HTML(req1.content)
uuid = sel.xpath(‘//input[@id=“uuid“]/@value‘)[0]
eid = sel.xpath(‘//input[@id=“eid“]/@value‘)[0]
sa_token = sel.xpath(‘//input[@id=“sa_token“]/@value‘)[0]
pubKey = sel.xpath(‘//input[@id=“pubKey“]/@value‘)[0]
t = sel.xpath(‘//input[@id=“token“]/@value‘)[0]
r = random.random()
login_url = ‘https://passport.jd.com/uc/loginService‘
class JD(object):
def __init__(selfusernamepasswordrk_usernamerk_pwd):
self.username = username
self.password = password
self.rkclient = RClient(rk_usernamerk_pwd)
self.trackid = ‘‘
self.pid = ‘‘
# 账号登录函数
def login(self):
params = {
‘uuid‘:uuid
‘eid‘:eid
# ‘fp‘:‘a2fd52211772d8fea0515bedca560b0b‘
‘_t‘:t
‘loginType‘:‘c‘
‘loginname‘:self.username
‘nloginpwd‘:self.password
‘chkRememberMe‘:‘‘
‘authcode‘:‘‘
‘pubKey‘:pubKey
‘sa_token‘:sa_token
# ‘seqSid‘:‘5574250748814772000‘
}
headers = {
‘Referer‘:‘https://passport.jd.com/uc/login?ltype=logout‘
‘User-Agent‘:‘Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_2) AppleWebKit/537.36 (KHTML like Gecko) Chrome/55.0.2883.95 Safari/537.36‘
‘X-Requested-With‘:‘xmlHttpRequest‘
}
# 验证码图片
imgcode = ‘http:‘ + sel.xpath(‘//img[@id=“JD_Verification1“]/@src2‘)[0]
img = requests.get(imgcode)
# 把这个路径替换成自己电脑jd.py文件夹的路径,/Users/zhangkai/Desktop/JD
with open(‘/Users/zhangkai/Desktop/JD/a.jpg‘ ‘wb‘) as f:
f.write(img.content)
im = open(‘a.jpg‘‘rb‘).read()
print(‘开始识别验证码...‘)
# print(imgcode) # 手动验证码连接
# 自动打码
imgcode1 = self.rkclient.rk_create(im 3040)[‘Result‘]
print(imgcode1)
if imgcode != ‘‘:
# params[‘authcode‘] = input(‘请输入验证码:‘) # 手动输验证码
params[‘authcode‘] = str(imgcode1)
req2 = s.post(login_url data=params headers=headers)
patt = ‘ ‘
self.trackid = re.compile(patt).findall(str(s.cookies))
js = json.loads(req2.text[1:-1])
if js.get(‘success‘):
print(‘登录成功‘)
else:
print(‘登录失败‘)
else:
req2 = s.post(login_url data=params headers=headers)
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2017-05-05 11:47 JD_AutoSubmit-master\
文件 1253 2017-05-05 11:47 JD_AutoSubmit-master\README.md
文件 8376 2017-05-05 11:47 JD_AutoSubmit-master\jd.py
文件 1588 2017-05-05 11:47 JD_AutoSubmit-master\rk.py
相关资源
- Python-京东抢购助手包含登录查询商品
- Python-利用Python图虫网摄影作品
- ScrapyMySQL爬取链家网中北京地区租房信
- Python-网站图片爬虫已包含微博微信公
- Python-WenshuSpiderScrapy框架爬取中国裁判
- Python-智联51job招聘需求挖掘采集和分
- Python-指定用户的所有抖音视频以及收
- Python-淘宝天猫商品数据抓取代码和
- Python-Boss直聘Python招聘岗位信息爬取和
- Python-精准的百度指数抓取综合已有百
- Python-百度指数爬虫可以自定义时间段
- Python-爬取各种开源软件的官方仓库历
- Python-微信公众号历史文章爬取api
- Python-readwx爬取微信公众号爬取搜狗微
- Python-指定的抖音Douyin号的视频抖音爬
- Python-用于爬取万方数据库文献摘要数
- Python-爬取微信公众号文章
评论
共有 条评论