如果新页面打印相同的URL,并且经常在下一次点击时卡住

时间:2017-12-03 06:40:18

标签: python python-3.x selenium selenium-webdriver

我注意到selenium会在我点击下一个按钮时更改页面时保持打印当前URL。

我错过了什么吗?它似乎正确遍历所有页面,但driver.current url每次都是相同的。怎么可能?我忘了喝早晨的咖啡..

我也注意到它经常出现故障而不是点击下一步它只是显示一个像这样的小图标。这两个问题可能相关吗?

enter image description here

driver = webdriver.Chrome()
driver.maximize_window()
driver.get('https://github.com/scrapy/scrapy/issues?page=1&q=is%3Aissue+is%3Aopen')

        elements = driver.find_elements_by_css_selector("div > div.float-left.col-9.p-2.lh-condensed > a")
elem_href1 = [element.get_attribute("href") for element in elements]
for link in elem_href1:
    try:
        directory = 'C:\\Users\\fefs.csv'
        with open(directory, 'a', newline='', encoding="utf-8") as outfile:
            writer = csv.writer(outfile)
            time.sleep(2)

            langs_text = driver.current_url
            print(langs_text)
            writer.writerow(langs_text)

            SCROLL_PAUSE_TIME = 0.5

            last_height = driver.execute_script("return document.body.scrollHeight")

            while True:

                driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")

                time.sleep(SCROLL_PAUSE_TIME)

                new_height = driver.execute_script("return document.body.scrollHeight")
                if new_height == last_height:
                    break
                last_height = new_height
            time.sleep(2)
            wait(driver, 10).until(
            EC.element_to_be_clickable((By.CSS_SELECTOR, ("#js-repo-pjax-container > div.container.new-discussion-timeline.experiment-repo-nav > div.repository-content > div > div.paginate-container > div > a.next_page")))).click()

0 个答案:

没有答案