解析结果网页Python Selenium

阿本

我在Python中使用了Selenium Webdriver在搜索字段中输入了一些文本并寻找它。我现在想解析该页面/在其上使用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()
斯特凡·布鲁克特(StéphaneBruckert)

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

submit.click()

它会自动转到下一页。因此,要解析生成的页面,只需再做一个:

whatimlookingfor = driver.find_element_by_id("myid")

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")

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章