繁体   English   中英

当我执行driver.get(url)时,Selenium将我重定向回到起始页面

[英]Selenium redirects me back to the starting page when i do driver.get(url)

我在单击“提交”按钮后,正在抓取此网页: http ://www.cpcb.gov.in/CAAQM/frmReportdisplay.aspx,页面内容会更改,而url保持不变。 我想访问那些内容,但是当我执行print(driver.current_url)时,却看不到起始页的内容。 我如何访问这些内容?

提交后:页面内容就是这个。

在此处输入图片说明

from bs4 import BeautifulSoup
import sys
from selenium import webdriver
from selenium.webdriver.support.ui import Select
import time 
chromedriver_loc = '/home/ninjakx/Desktop/mywork/chromedriver-Linux64' 
# enter path of chromedriver
driver = webdriver.Chrome(executable_path=chromedriver_loc)
url ="http://www.cpcb.gov.in/CAAQM/frmUserAvgReportCriteria.aspx"
driver.get(url)

select = Select(driver.find_element_by_id('ddlState'))
# select by visible text
select.select_by_visible_text('Delhi')
time.sleep(10)
select = Select(driver.find_element_by_id('ddlCity'))
select.select_by_visible_text('Delhi')
time.sleep(5)
select = Select(driver.find_element_by_id('ddlStation'))
select.select_by_visible_text('Dwarka')
time.sleep(10)

your_choice.click()
driver.find_element_by_xpath('//*[@id="btnAdd"]').click()
time.sleep(13)
your_choice=driver.find_element_by_xpath("//select[@id='lstBoxChannelLeft']/option[@value='874']")
your_choice.click()
driver.find_element_by_xpath('//*[@id="btnAdd"]').click()
time.sleep(13)
your_choice=driver.find_element_by_xpath("//select[@id='lstBoxChannelLeft']/option[@value='1366']")
your_choice.click()
driver.find_element_by_xpath('//*[@id="btnAdd"]').click()
time.sleep(13)
your_choice=driver.find_element_by_xpath("//select[@id='lstBoxChannelLeft']/option[@value='1377']")

your_choice.click()
driver.find_element_by_xpath('//*[@id="btnAdd"]').click()
time.sleep(13)
your_choice=driver.find_element_by_xpath("//select[@id='lstBoxChannelLeft']/option[@value='864']")
your_choice.click()
driver.find_element_by_xpath('//*[@id="btnAdd"]').click()
time.sleep(13)
your_choice=driver.find_element_by_xpath("//select[@id='lstBoxChannelLeft']/option[@value='824']")
your_choice.click()
driver.find_element_by_xpath('//*[@id="btnAdd"]').click()
time.sleep(13)
your_choice=driver.find_element_by_xpath("//select[@id='lstBoxChannelLeft']/option[@value='502']")
your_choice.click()
driver.find_element_by_xpath('//*[@id="btnAdd"]').click()
time.sleep(13)

datefield = driver.find_element_by_xpath('//*[@id="txtDateFrom"]')
datefield.click()
datefield.clear()
datefield.send_keys("01/01/2017")
time.sleep(2)
driver.find_element_by_xpath('//*[@id="btnSubmit"]').click()
time.sleep(5)
cur_url = driver.current_url
driver.get(url)
time.sleep(20)

这不仅仅是输入错误吗?

您输入:

driver.find_element_by_xpath('//*[@id="btnSubmit"]').click()
time.sleep(5)
cur_url = driver.current_url
driver.get(url)

我认为应该是:

driver.find_element_by_xpath('//*[@id="btnSubmit"]').click()
time.sleep(5)
cur_url = driver.current_url
driver.get(cur_url) #changed here

我不必再次访问该链接。只需继续编写脚本来获取数据。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM