Selenium Post method

爷,独闯天下 提交于 2020-05-26 04:36:07

问题


I'm trying to find a way to get the response of a post method executed through headless browser.

session = requests.Session()
session.get(<url here)
print session.cookies
r = session.post(url).content
print r

The problem is that the response r is full of javascript and I can't use Selenium to execute it because it doesn't support the POST method (as far as I know). Any ideas?


回答1:


You can try using selenium-requests:

Extends Selenium WebDriver classes to include the request function from the Requests library, while doing all the needed cookie and request headers handling.

Example:

from seleniumrequests import Firefox

webdriver = Firefox()
response = webdriver.request('POST', 'url here', data={"param1": "value1"})
print(response)


来源:https://stackoverflow.com/questions/34964423/selenium-post-method

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!