以下代码可帮助我使用selenium
导航到某个页面,然后点击“查看所有公司”按钮
path_to_chromedriver = r'C:\Users\chromedriver.exe'
driver = webdriver.Chrome(executable_path=path_to_chromedriver)
driver.get(r'http://sgx.com/wps/portal/sgxweb/home/company_disclosure/stockfacts')
wait = WebDriverWait(driver, 25)
# locate and switch to the iframe
iframe = driver.find_element_by_css_selector("#mainContent iframe")
driver.switch_to.frame(iframe)
# wait for the table to load
wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, '.companyName')))
# Select All Companies
element1 = driver.find_element_by_css_selector('span[data-name*="all-companies"]')
element1.click()
time.sleep(5)
然而,当我尝试print(driver.page_source)
时,它会首先打印出来源,然后会出现错误信息:
ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host
有什么建议吗?