python - 知乎上的个人详细页面post地址怎么找

 郑雅琳RaeiHh 发布于 2022-11-03 22:17

我处理的时候出现以下内容的:

每次点击修改内容,都会出现ProfileHeaderV2这个链接信息,但访问是404的,
然后又提示post信息却又是这个地址,这是为咋的?

======================

补充代码

# /usr/bin/python
#coding:utf-8
__author__ = 'eyu Fanne'

import requests,time
from bs4 import BeautifulSoup

begintime = time.time()



headers={
    "Host":"www.zhihu.com",
    "User-Agent":"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.111 Safari/537.36",
    "Accept":"*/*",
    "Accept-Language":"zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3",
    "Accept-Encoding":"gzip, deflate",
    "Content-Type":"application/x-www-form-urlencoded; charset=UTF-8",
    "X-Requested-With":"XMLHttpRequest",
    "Connection":"keep-alive"
}


login_url=r'https://www.zhihu.com/login/email'

html_txt = requests.get(login_url,verify=False).text
html_soup = BeautifulSoup(html_txt,'lxml')
xsrf = html_soup.find("input",{"name":"_xsrf"})['value']

#print xsrf
#print html_txt
s = requests.session()

url_data={
    "_xsrf":xsrf,
    "email":"*****",
    "password":"*****",
    'remember_me':'true'
}

s_login=s.post(login_url,data=url_data,headers=headers,verify=False)
print s_login.text

# endtime = time.time()
# usetime =  endtime - begintime
# print "执行脚本总用时 %s 秒" % usetime


#print s.get('https://www.zhihu.com',verify=False).text

#修改个人简介

edit_url=r'https://www.zhihu.com/node/ProfileHeaderV2'
peplo_url=r'https://www.zhihu.com/people/shui-di-you/about'
edit_html_txt = s.get(peplo_url,verify=False).text
#print edit_html_txt.text

exit_html_soup = BeautifulSoup(edit_html_txt,'lxml')
edit_xsrf = exit_html_soup.find("input",{"name":"_xsrf"})['value']
print 'edit_xsrf:%s' %edit_xsrf

edit_url_data={
    "_xsrf":edit_xsrf,
    "method":"save",
    "params":{"data":{"description":"233333~~~"}}
}


edit_header={
    "Host":"www.zhihu.com",
    "User-Agent":"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.111 Safari/537.36",
    "Accept":"*/*",
    "Accept-Language":"zh-CN,zh;q=0.8",
    "Accept-Encoding":"gzip, deflate",
    "Content-Type":"application/x-www-form-urlencoded; charset=UTF-8",
    "X-Requested-With":"XMLHttpRequest",
    "Connection":"keep-alive",
    "Origin":"https://www.zhihu.com",
    "Referer":"https://www.zhihu.com/people/shui-di-you/about"
}
s_edit=s.post(edit_url,data=edit_url_data,headers=edit_header,verify=False)
print s_edit

最后s_edit得到的结果是

{"r":0,
 "msg": "\u767b\u9646\u6210\u529f"
}



Process finished with exit code 0

搞定了,把参数params = json.dumps({"data":{"description":"233333~~~"}})
转一下json格式就好了

3 个回答
  • POST带的参数是什么,建议用Wireshark抓两个包,一个是知乎页面上修改时的POST包,另外是你用python POST的包,查看具体区别。

    2022-11-06 11:09 回答
  • 你的请求的 Remote Address 为什么会是本地的 127.0.0.1:8888?

    这个地址要带参数去访问才是正常的,不然服务器返回什么都是有可能的。

    2022-11-06 11:12 回答
  • 可能是Post数据的事吧,可能Post绑定方法了,Get的没绑定

    2022-11-06 11:13 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有