import requests
from selenium import webdriver
from selenium.webdriver.common.by import By
from VerificationcodeProcessing import YdmVerify
import json
def getHTMLText(url):
try:
headers={'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.5112.102 Safari/537.36 Edg/104.0.1293.63'}
res=requests.get(url,headers=headers)
print(res)
res.raise_for_status()
return res.content
except:
return ""
d = webdriver.Edge()
d.get('https://so.gushiwen.cn/user/login.aspx?')
username = d.find_element(By.ID,"email").send_keys("15128325796")
password = d.find_element(By.ID,"pwd").send_keys("123456789")
YdmVerify1 = d.find_element(By.ID,"imgCode")
url =YdmVerify1.get_attribute("src")
print(url)
text = getHTMLText(url)
with open("验证码识别.jpg","wb") as f:
f.write(text)
Y = YdmVerify()
with open('验证码识别.jpg', 'rb') as f:
s = f.read()
da = Y.common_verify(s, verify_type="10110")['data']['data']
#print(type(da),da)
YdmVerify1 = d.find_element(By.ID,"code").send_keys(da)
denglu = d.find_element(By.ID,"denglu").click()