import requests
import json
from time import sleep class Test:
url= "http://www.cnblogs.com/"
headers={
"User - Agent": "Mozilla / 5.0(Windows NT 10.0;WOW64;rv: 60.0) Gecko / 20100101Firefox / 60.0"
}
s = requests.session()
r = s.get(url,headers=headers)
# print(s.cookies)
# print(r.cookies) cook = r.cookies
cook.set('.CNBlogsCookie','C76B27C42D3ADA95CE6D77F29F1F6357BAC46EE05966C386344EACD3FBDDA5E2D6DD0470DAF37AB7BF1B66189003227A42A0A1940F27A281B05F11524023CB4692A0DAAC13E4B4E802D24763A9804F2616562989'),
cook.set('.Cnblogs.AspNetCore.Cookies',
'CfDJ8Gf3jjv4cttDnEy2UYRcGZ1_zoJHOThA8xGirB4nGc2hvBD8zDQW4s-DzbOSywo0GuAwDJ3Fo8fxDy6brKcEMQk1ipNocDiGpNHWcQM7CXM_YByoFYEelH20c-cTAum_1sL-mJ5c1ydjJYVxmIOcYcKCx0BtNKC0SLlzMBzaC1sHhvUTRQv2ETGU6lljuBwpH7TCMfDLHqi1thlHAHCNo5nxyrnB5S1MJ64bHALoOKuUKAEtZqyQ4WZ3pH00dt5Oq7MzUgVunS-kIGhJ83g-c4QDDULwCihkewLYMKDPrbuhPsMymexgus1Ey7uQxwN5Gg')
cook.set('AlwaysCreateItemsAsActive', "True")
cook.set('AdminCookieAlwaysExpandAdvanced', "True")
s.cookies.update(cook)
print(s.cookies)
r1 = s.get(url)
url3 = "https://i.cnblogs.com/EditPosts.aspx?opt=1"
# body ={
# "__VIEWSTATE":"",
# "__VIEWSTATEGENERATOR":"FE27D343",
# "Editor$Edit$txbTitle":"lalalal",
# "Editor$Edit$EditorBody": "< p > lalalladslkjds哈哈 < / p >",
# "Editor$Edit$Advanced$ckbPublished":"on",
# "Editor$Edit$Advanced$chkDisplayHomePage":"on",
# "Editor$Edit$Advanced$chkComments":"on",
# "Editor$Edit$Advanced$chkMainSyndication":"on",
# "Editor$Edit$Advanced$txbEntryName":"",
# "Editor$Edit$Advanced$txbExcerpt":"",
# "Editor$Edit$Advanced$txbTag":"",
# "Editor$Edit$Advanced$tbEnryPassword":"",
# "Editor$Edit$lkbPost":"发布"
# } # body1 = {"__VIEWSTATE": "",
# "__VIEWSTATEGENERATOR": "FE27D343",
# "Editor$Edit$txbTitle": "这是3111",
# "Editor$Edit$EditorBody": "<p>这里111:http://www.cnblogs.com/yoyoketang/</p>",
# "Editor$Edit$Advanced$ckbPublished": "on",
# "Editor$Edit$Advanced$chkDisplayHomePage": "on",
# "Editor$Edit$Advanced$chkComments": "on",
# "Editor$Edit$Advanced$chkMainSyndication": "on",
# "Editor$Edit$Advanced$txbEntryName": "",
# "Editor$Edit$Advanced$txbExcerpt": "",
# "Editor$Edit$Advanced$tbEnryPassword": "",
# "Editor$Edit$lkbDraft": "存为草稿",
# } # r3 = requests.post(url3, body1, verify=False)
# sleep(2)
print(r1.text)
注意:登陆后的cookie值需要通过抓包工具获取; 对比登陆前后的cookie值就可以找出;