import requests
headers = {'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36 Edg/85.0.564.63'}
login_data={
'log': 'codetime',
'pwd': 'shanbay520',
'wp-submit': '登录',
'redirect_to': 'https://wpblog.x0y1.com',
'testcookie': '1'
}
comment_data={
'comment': '小贝贝,我来啦',
'submit': '发表评论',
'comment_post_ID': '34',
'comment_parent': '0'
}
#模拟登录
login = requests.post('https://wpblog.x0y1.com/wp-login.php',data=login_data,headers=headers)
print(login.status_code)
#模拟发表评论
comment=requests.post('https://wpblog.x0y1.com/wp-comments-post.php',cookies=login.cookies,data=comment_data,headers=headers)
print(comment.status_code)
爬虫模拟登录和发表评论
最新推荐文章于 2021-05-14 15:52:59 发布