python - selenium怎么样获得百度贴吧动态加载的组件?
PHP中文网
PHP中文网 2017-04-18 09:20:08
0
1
386

我想点击下面图片的回复,点击回复展开后输入(百度贴吧)

我不知道如何获得这个“回复”,加载页面完成后的page_source没有这部分的源码,所以我改怎么办呢??大牛求告知

或者可以直接post???

PHP中文网
PHP中文网

认证0级讲师

reply all(1)
Ty80

You already know it’s ajax, how can you use page source? You can use the "Inspect" function of Chrome browser.


Check to see what you are currently seeing in your browser! ! !

------------------------One more thing---------------------- --
Looking at your needs, you probably want to write a program to post replies in the post bar. I think you don’t need to use selenium.

This is the content captured by the packet capture in chrome when I submitted it, which is the content you submitted in the post.
Every item here can be obtained in the "Check" on the current page.
Then you can use python to simulate browser submission.

import requests

data = {'kw':'行尸走肉','fid':'815816'}  # 自行补充,
url = 'http://tieba.baidu.com/f/commit/post/add' # 在 headers 里有
cookies =  'your_cookies' #把抓包的Headers 里的 cookie 复制整理到这里

#为了防止百度禁止机器人,把 请求里的header 里的 user_agent 改一下。
headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.8 Safari/537.36'}
result = requests.post(url,data = data,cookies = cookies,headers = headers)
print(result.status_code) # 返回状态 
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!