python3接口自动化:绕过验证码登陆

 1 import requests
 2 import json
 3 from time import sleep
 4 
 5 class Test:
 6     url= "http://www.cnblogs.com/"
 7     headers={
 8         "User - Agent": "Mozilla / 5.0(Windows NT 10.0;WOW64;rv: 60.0) Gecko / 20100101Firefox / 60.0"
 9     }
10     s = requests.session()
11     r = s.get(url,headers=headers)
12     # print(s.cookies)
13     # print(r.cookies)
14 
15     cook = r.cookies
16     cook.set('.CNBlogsCookie','C76B27C42D3ADA95CE6D77F29F1F6357BAC46EE05966C386344EACD3FBDDA5E2D6DD0470DAF37AB7BF1B66189003227A42A0A1940F27A281B05F11524023CB4692A0DAAC13E4B4E802D24763A9804F2616562989'),
17     cook.set('.Cnblogs.AspNetCore.Cookies',
18              'CfDJ8Gf3jjv4cttDnEy2UYRcGZ1_zoJHOThA8xGirB4nGc2hvBD8zDQW4s-DzbOSywo0GuAwDJ3Fo8fxDy6brKcEMQk1ipNocDiGpNHWcQM7CXM_YByoFYEelH20c-cTAum_1sL-mJ5c1ydjJYVxmIOcYcKCx0BtNKC0SLlzMBzaC1sHhvUTRQv2ETGU6lljuBwpH7TCMfDLHqi1thlHAHCNo5nxyrnB5S1MJ64bHALoOKuUKAEtZqyQ4WZ3pH00dt5Oq7MzUgVunS-kIGhJ83g-c4QDDULwCihkewLYMKDPrbuhPsMymexgus1Ey7uQxwN5Gg')
19     cook.set('AlwaysCreateItemsAsActive', "True")
20     cook.set('AdminCookieAlwaysExpandAdvanced', "True")
21     s.cookies.update(cook)
22     print(s.cookies)
23     r1 = s.get(url)
24     url3 = "https://i.cnblogs.com/EditPosts.aspx?opt=1"
25     # body ={
26     #     "__VIEWSTATE":"",
27     #     "__VIEWSTATEGENERATOR":"FE27D343",
28     #     "Editor$Edit$txbTitle":"lalalal",
29     # "Editor$Edit$EditorBody": "< p > lalalladslkjds哈哈 < / p >",
30     # "Editor$Edit$Advanced$ckbPublished":"on",
31     # "Editor$Edit$Advanced$chkDisplayHomePage":"on",
32     # "Editor$Edit$Advanced$chkComments":"on",
33     # "Editor$Edit$Advanced$chkMainSyndication":"on",
34     # "Editor$Edit$Advanced$txbEntryName":"",
35     # "Editor$Edit$Advanced$txbExcerpt":"",
36     # "Editor$Edit$Advanced$txbTag":"",
37     # "Editor$Edit$Advanced$tbEnryPassword":"",
38     # "Editor$Edit$lkbPost":"发布"
39     # }
40 
41     # body1 = {"__VIEWSTATE": "",
42     #         "__VIEWSTATEGENERATOR": "FE27D343",
43     #         "Editor$Edit$txbTitle": "这是3111",
44     #         "Editor$Edit$EditorBody": "

这里111:http://www.cnblogs.com/yoyoketang/

",
45 # "Editor$Edit$Advanced$ckbPublished": "on", 46 # "Editor$Edit$Advanced$chkDisplayHomePage": "on", 47 # "Editor$Edit$Advanced$chkComments": "on", 48 # "Editor$Edit$Advanced$chkMainSyndication": "on", 49 # "Editor$Edit$Advanced$txbEntryName": "", 50 # "Editor$Edit$Advanced$txbExcerpt": "", 51 # "Editor$Edit$Advanced$tbEnryPassword": "", 52 # "Editor$Edit$lkbDraft": "存为草稿", 53 # } 54 55 56 # r3 = requests.post(url3, body1, verify=False) 57 # sleep(2) 58 print(r1.text)

 注意:登陆后的cookie值需要通过抓包工具获取; 对比登陆前后的cookie值就可以找出;

转载于:https://www.cnblogs.com/lelexiong/p/9116411.html

你可能感兴趣的:(python3接口自动化:绕过验证码登陆)