From f07ae934ccbdec9378b46f6d7686a0a155ca6866 Mon Sep 17 00:00:00 2001 From: JLUVicent <17390955615@163.com> Date: Thu, 16 Sep 2021 10:58:22 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=B3=E4=BA=8E=E9=AA=8C=E8=AF=81=E7=A0=81?= =?UTF-8?q?=E7=99=BB=E5=BD=95=E9=97=AE=E9=A2=98=E7=94=A8session?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...44\350\257\227\346\226\207\347\275\221.py" | 93 ++++++++++ code.jpg | Bin 0 -> 1432 bytes gushiwen.html | 162 ++++++++++++++++++ 3 files changed, 255 insertions(+) create mode 100644 "34_request_cookie\347\231\273\351\231\206\345\217\244\350\257\227\346\226\207\347\275\221.py" create mode 100644 code.jpg create mode 100644 gushiwen.html diff --git "a/34_request_cookie\347\231\273\351\231\206\345\217\244\350\257\227\346\226\207\347\275\221.py" "b/34_request_cookie\347\231\273\351\231\206\345\217\244\350\257\227\346\226\207\347\275\221.py" new file mode 100644 index 0000000..28d96e3 --- /dev/null +++ "b/34_request_cookie\347\231\273\351\231\206\345\217\244\350\257\227\346\226\207\347\275\221.py" @@ -0,0 +1,93 @@ + +# 通过登陆 进入到主页面 + + +# 通过找登陆接口发现登陆时候需要的参数很多在login中找 + +# __VIEWSTATE: kBeYlQh4JeI1J7uQdLrUffn6FHUW2mJE8dKQYKQypdnw4kIi6ZE63qg6WoLKkbeVKkpzY+XGF3E2dB/e4nViUEKrd7gvgC4uyMiNOUcKptmPrYXxO0hgkpyZhIQ= +# __VIEWSTATEGENERATOR: C93BE1AE +# from: http://so.gushiwen.cn/user/collect.aspx +# email: 17390955615@163.com +# pwd: 1233312 +# code: z0x6 +# denglu: 登录 + +# 观察到__VIEWSTATE, __VIEWSTATEGENERATOR,以及code是变化的 + + +# 难点:(1)__VIEWSTATE, __VIEWSTATEGENERATOR 一般情况下看不到的数据都在页面的源码中 +# 观察到两个数据在页面的源码中,因此我们需要获取页面的源码然后进行解析就可以了 +# (2)验证码 +import urllib.request +from bs4 import BeautifulSoup +import requests + +# 登陆页面的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' +} + +# 获取页面的源码 +response = requests.get(url=url, headers=headers) +content = response.text + +# print(content) + +# 解析页面源码获取__VIEWSTATE, __VIEWSTATEGENERATOR的值 + + +soup = BeautifulSoup(content, 'lxml') + +# 获取__VIEWSTATE +viewstate = soup.select('#__VIEWSTATE')[0].attrs.get('value') + +# 获取__VIEWSTATEGENERATOR的值 +viewstategenerator = soup.select('#__VIEWSTATEGENERATOR')[0].attrs.get('value') + + +# 获取验证码图片 + +code = soup.select('#imgCode')[0].attrs.get('src') +# print(code) + +code_url = 'https://so.gushiwen.cn'+code +# print(code_url) + +# 有坑 +# urllib.request.urlretrieve(url=code_url, filename='code.jpg') + +# requests里面有一个方法交session(),通过session的返回值就能使得请求变成对象 +session = requests.session() +# 验证码的url的内容 +response_code = session.get(code_url) +# 注意此时要使用二进制数据,因为我们要使用图片的瞎子啊 +content_code = response_code.content +# wb模式是将二进制数据写入文件 +with open('code.jpg', 'wb')as fp: + fp.write(content_code) + +# 获取验证码的图片之后下载到本地观察验证码在控制台输入验证码可以将值赋给code参数 +code_name = input('请输入你的验证码:') + +# 点击登录 + +url_post = 'https://so.gushiwen.cn/user/login.aspx?from=http%3a%2f%2fso.gushiwen.cn%2fuser%2fcollect.aspx' + +data_post = { + '__VIEWSTATE': viewstate, + '__VIEWSTATEGENERATOR': viewstategenerator, + 'from': 'http://so.gushiwen.cn/user/collect.aspx', + 'email': '17390955615@163.com', + 'pwd': '2bldhbfh', + 'code': code_name, + 'denglu': '登录', +} + +response_post = session.post(url=url, headers=headers, data=data_post) + +content_post = response_post.text + +with open('gushiwen.html', 'w', encoding='utf-8')as fp: + fp.write(content_post) diff --git a/code.jpg b/code.jpg new file mode 100644 index 0000000000000000000000000000000000000000..615709cc5f9cb99bcaa1d354ab4a91901532b766 GIT binary patch literal 1432 zcmXYweN5L?6vj^o3q?~5P?FXR#Fq<(9xIKxCGH2I`GRrB~m68(g;CB z92tm#86+aY2G}4QV#92Njj{!{$d=eLTVbp0fE}_UcFa!LDSKd#?1??I7xu~lI3Ne& zz#N2wvH~lz5-YO`YeYXX8wE&!1tc;<42VH7B!Uy=(2WQ|Mb`kxl=Z+8@g;^*{If)>09EaAIlqm<5I4Vdu>KZV?yHg zH=lZ?=b#<~=XUFG@5iH;W^|a-ynX+!PDw*svzkBa{`%d`mGeH%$xlz-IAY8jiM2KU zU?ve(aauYxAfcU$)hsx^VVDZ2tHg=PG-5>$0)w ztG0HZe&uRg>d?IAIebp~ZPF!+e{QTYx9rd1l<#!#On0I9Foo{U$^k`b{ z9nWuzThrL^!}5>Hle?r27`x}bgdSzpHy%4)P?54?RYUFBZFLK?UrgAwAbWXB+KQ}0 z)3OeYPTMi^>!kQj1yJ|KwBrRccK?`Fo^+&7W@Gk^7gtWpxW04Cqp@D6;(wiYx%2j} z!%q+UVq9i!``TrXbLWxeL)!LLALy0Wu{ze{(wU;Fnd$Rq*t+ue!sJIT&OTk1QSiXQ z1=+jLWKOHTHo13U>h#3o$usjNoLrPtbiV2Rga^*eI($b;pIIk!b6VFG=jTi4@S{edmApTmG26v9GhsC)7Wb^vwC1vcVhD=|EF!MxWxQN%egW6D;Yj($LzXW z3-_dR)!08fe;c>4VeiIcJu7XW+QA>(R(f#Mv)SQD$Zd2P&)&1Y_FTcjlE%~Y-V;lA`K + + +我的收藏_古诗文网 + + + + + + + + + + +
+
+ +
+ +
+ +
+
+
+
+
+
+
+我的收藏 +/ +我的背诵 +字母排序 +/ +时间排序 +
+
+账号管理 +
+
+
+ +
+收藏教程 +
+
+下一页 +上一页 +/ 1页 + + + + + +
+
+
+
+ + + +
+

扫码下载

古文岛客户端

+
+
+

扫码关注

古文岛公众号

+
+
+
+ + + + +