python爬虫实战

#coding=utf-8
import requests
import execjs
from time import sleep
from random import randint
import ddddocr
import os
from pdb import set_trace
from pprint import pprint
from urllib.parse import urljoin
from bs4 import BeautifulSoup
from selenium import webdriver
from selenium.webdriver.common.by import By
uiName="Project1"
ElementBGArray={}  
ElementBGArray_Resize={} 
ElementBGArray_IM={} 

def Button_1_onCommand():
    
    session = requests.Session()
    
    headers = {
        "Accept": "application/json, text/plain, */*",
        "Accept-Language": "zh-CN,zh;q=0.9",
        "Connection": "keep-alive",
        "Content-Type": "application/x-www-form-urlencoded",
        "Origin": "https://login.dangdang.com",
        "Referer": "https://login.dangdang.com/?returnurl=https%3A%2F%2Fwww.dangdang.com%2F",
        "Sec-Fetch-Dest": "empty",
        "Sec-Fetch-Mode": "cors",
        "Sec-Fetch-Site": "same-origin",
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36",
        "sec-ch-ua": "\"Chromium\";v=\"124\", \"Google Chrome\";v=\"124\", \"Not-A.Brand\";v=\"99\"",
        "sec-ch-ua-mobile": "?0",
        "sec-ch-ua-plat form": "\"Windows\""
    }
    proxy={'http':'http://117.71.132.220:8089'}
    browser=webdriver.Chrome()
    browser.get('https://login.dangdang.com/?returnurl=https%3A%2F%2Fwww.dangdang.com%2F#')
    set_trace()
    for code in range(50):
    
        with open('temp.js', 'r', encoding='utf-8') as f:
            js = f.read()
        js1 = execjs.compile(js).call('main')
        
        url = 'https://login.dangdang.com/api/customer/loginapi/getRankey'
        js1['t'] = str(js1['t'])
        res = session.post(url, headers=headers, data=js1).json()
        t = {
            "situation": "login"
        }
        with open('temp2.js', 'r', encoding='utf-8') as f:
            js = f.read()
        js = execjs.compile(js).call('main', js1['permanent_id'], res['requestId'], res['rankey'], t)
        js['t'] = str(js['t'])
        
        data, jsres = js,res
        url = 'https://login.dangdang.com/api/customer/loginapi/getSlidingVerifyCode'
        res = session.post(url, data=data, headers=headers).json()
        滑块 = requests.get(res['data']['slideImg']).content
        背景 = requests.get(res['data']['bgImg']).content
        ocr = ddddocr.DdddOcr(det=False, ocr=False, show_ad=False)
        xy = ocr.slide_match(背景,滑块,simple_target=True)
        x = xy['target'][0] - 20
        y = res['data']['y']
        token = res['data']['token']
        encryptKey = res['data']['encryptKey']
        permanent_id = data['permanent_id']
        requestId = data['requestId']
        rankey = jsres['rankey']
        time = randint(800, 4000)
        with open('temp3.js', 'r', encoding='utf-8') as f:
            js = f.read()
        data = execjs.compile(js).call('mm', token, time, x, y, permanent_id, requestId, rankey, encryptKey)
        res = session.post('https://login.dangdang.com/api/customer/loginapi/checkSlidingVerifyCode', data=data, headers=headers).json()
        状态 = res['errorMsg']
        if 状态 == '成功':
            checkcode = res['data']["checkCode"]
            break
    checkcode, token, permanent_id, requestId, rankey =checkcode, token, permanent_id, requestId, rankey
    #username = Fun.GetText(uiName,"Entry_1")
    #password = Fun.GetText(uiName,"Entry_2")
    with open('temp3.js', 'r', encoding='utf-8') as f:
        js = f.read()
    #js = execjs.compile(js).call('passwd', username, password, token, checkcode, permanent_id, requestId, rankey)
    url = 'https://login.dangdang.com/api/customer/loginapi/accountLogin'
    s=session.post(url, headers=headers, data=js)
    sleep(randint(1,3))
    s=s.json()
    print(s)
    msg=s.get('errorMsg',True)
    if msg==True:
        pass
        #Fun.GoToUIDialog(uiName,'数据',params=session)
    else:
        pass
        #Fun.GoToUIDialog(uiName,'数据',params=session)
        #Fun.MessageBox(s['errorMsg'])
Button_1_onCommand()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值