有没有一种方法可以从Python应用程序打开浏览器,同时用POST方法将数据发送到浏览器?
我尝试使用webbrowser.open(url)
打开浏览器窗口,但我还需要向其中发送一些数据(通过post变量),以确保页面打开时包含正确的信息。
例如,我想打开http://duckduckgo.com,同时将"q=mysearchterm“作为POST数据发送到它,这样页面就会打开,其中包含预先填充的数据。
发布于 2018-08-02 06:59:59
我认为您应该使用像Selenium这样的Web驱动程序。下面是一个示例:
import time
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
browser = webdriver.Chrome(r"PATHTO\chromedriver.exe") # download the chromedriver and provide the full path here
browser.get('http://duckduckgo.com/')
search = browser.find_element_by_name('q')
search.send_keys("mysearchterm")
search.send_keys(Keys.RETURN)
time.sleep(15)
https://stackoverflow.com/questions/51643034
复制相似问题