When using selenium, the Web page is loaded for a long time

Source: Internet
Author: User

There are some Web pages loading time is very long, Xinhua will never load, but need to crawl the information has been loaded out, if it is time to wait to continue is a waste.

There will likely be a long time to load the place try except,

If the page needs to crawl content has been loaded, even if the page does not load complete, except after the driver can also be used

From selenium.common.exceptions import timeoutexception
Why the from selenium.common.exceptions.TimeoutException as TimeoutException cannot point out timeoutexception

                Try:try:driver.get ("https://c3.zgdhhjha.com/scholar/")  Except Timeoutexception,e:print type (e) print ' Time Out in
                        Search Page ' try:driver.find_element_by_id (' Gs_hdr_tsi '). Send_keys (Line[i])
                        Driver.find_element_by_xpath ('//*[@id = ' gs_hdr_tsb ']/span/span[1] '). Click () A = Driver.find_element_by_xpath ('//*[@id = "Gs_res_ccl_mid"]/div/div[2]/div[3]/a[3] ') except Timeoute Xception, E:print ' Time Out in crawl page ' with open (' Citaresult.txt ', ' a ') a S Wfile:wfile.write (str (i+1) + ', ' +a.text+ ' \ n ') except Exception, e:# here, you can tell if it is
                    No such element exception print ' Exception: ', e print ' num: ', I, ' title: ', Line[i] Driver.closE () chromedriver = ' F:\chromedriver_win32\chromedriver.exe ' # Chromedriver's path to the OS. environ["Webdriver.chrome.driver"] = chromedriver Driver = webdriver. Chrome (Chromedriver)





Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.