Skip to content

Commit

Permalink
cookie登录古诗文网注意自动识别验证码的使用
Browse files Browse the repository at this point in the history
  • Loading branch information
JLUVicent committed Sep 16, 2021
1 parent f07ae93 commit 1f9cbad
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions 34_request_cookie登陆古诗文网.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,24 @@
# 难点:(1)__VIEWSTATE, __VIEWSTATEGENERATOR 一般情况下看不到的数据都在页面的源码中
# 观察到两个数据在页面的源码中,因此我们需要获取页面的源码然后进行解析就可以了
# (2)验证码
import time
import urllib.request
from bs4 import BeautifulSoup
import requests
from chaojiying import Chaojiying_Client

# 登陆页面的Url地址
url = 'https://so.gushiwen.cn/user/login.aspx?from=http://so.gushiwen.cn/user/collect.aspx'

headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.63 Safari/537.36'
}
proxy = {
'http://': '27.44.214.169:4245'

}
# 获取页面的源码
response = requests.get(url=url, headers=headers)
response = requests.get(url=url, headers=headers, proxies=proxy)
content = response.text

# print(content)
Expand Down Expand Up @@ -67,9 +72,16 @@
# wb模式是将二进制数据写入文件
with open('code.jpg', 'wb')as fp:
fp.write(content_code)
time.sleep(3)

chaojiying = Chaojiying_Client(
'action', 'action', '922587') # 用户中心>>软件ID 生成一个替换 96001
im = open('code.jpg', 'rb').read() # 本地图片文件路径 来替换 a.jpg 有时WIN系统须要//
# 1902 验证码类型 官方网站>>价格体系 3.4+版 print 后要加()
code_num = chaojiying.PostPic(im, 1902).get('pic_str')
# 获取验证码的图片之后下载到本地观察验证码在控制台输入验证码可以将值赋给code参数
code_name = input('请输入你的验证码:')
code_name = code_num
# print(code_name)

# 点击登录

Expand All @@ -81,7 +93,7 @@
'from': 'http://so.gushiwen.cn/user/collect.aspx',
'email': '[email protected]',
'pwd': '2bldhbfh',
'code': code_name,
'code': str(code_name),
'denglu': '登录',
}

Expand Down

0 comments on commit 1f9cbad

Please sign in to comment.