Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/291.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 解析生成的网页_Python_Html_Selenium_Selenium Webdriver_Beautifulsoup - Fatal编程技术网

Python 解析生成的网页

Python 解析生成的网页,python,html,selenium,selenium-webdriver,beautifulsoup,Python,Html,Selenium,Selenium Webdriver,Beautifulsoup,我使用Python中的SeleniumWebDriver在搜索字段中输入一些文本并查找它。我现在想解析该页面/在其上使用类似BeautifulSoup的内容。但我不知道如何调用生成的页面 到目前为止,我的代码是: textinput = open("1.txt", "r").read() url = "http://www.example.com" driver = webdriver.Chrome(executable_path='path/chromedriver.exe') driver.

我使用Python中的SeleniumWebDriver在搜索字段中输入一些文本并查找它。我现在想解析该页面/在其上使用类似BeautifulSoup的内容。但我不知道如何调用生成的页面

到目前为止,我的代码是:

textinput = open("1.txt", "r").read()
url = "http://www.example.com"
driver = webdriver.Chrome(executable_path='path/chromedriver.exe')
driver.get(url)
sbox = driver.find_element_by_name("a")
sbox.send_keys(textinput)

submit = driver.find_element_by_xpath('//*[@id="maincontent"]/form/input[5]')
submit.click()

单击“提交”按钮后,请使用:

submit.click()
它会自动转到下一页。因此,要解析生成的页面,只需进行另一个:

whatimlookingfor = driver.find_element_by_id("myid")


当你输入文本后,用鼠标点击一些按钮,如“go”、“search”或其他可以打开结果页面的按钮。然后可以使用该页面的源代码提取数据。请分享你的想法code@Vipul请查找添加的代码。我能得到结果。但我需要解析它。我无法手动复制结果页面的URL,因为这样做了数百次。我想让它自动化。使用
driver.source
您可以获取源代码,您也不需要获取源代码或使用beautifulsoup,使用selenium驱动程序对象本身进行解析就足够了,而且非常干净,可以在
驱动程序中使用类、id、标记、xpath。按
查找元素或“驱动程序.按.\u查找元素”
submit = driver.find_element_by_xpath('//*[@id="maincontent"]/form/input[5]')
# You are still on the first page
submit.click()
# You are now on the second page
whatimlookingfor = driver.find_element_by_id("myid")