我需要阅读网页列表。例如,我有一个有效的网站
url1 = 'https://www.sia.ch/en/membership/member-directory/m/207778/'
driver = webdriver.Chrome('/Users/massaro/research/Valeria/chromedriver 2')
driver.get(url1)
html = driver.page_source
html = str(html).replace('<br />', '::')
df1 = pd.read_html(html)[0].iloc[[0,2],1]
而不是我收到另一个错误页面
url2 = 'https://www.sia.ch/en/membership/member-directory/m/105531/'
driver = webdriver.Chrome('/Users/massaro/research/Valeria/chromedriver 2')
driver.get(url2)
html = driver.page_source
html = str(html).replace('<br />', '::')
df1 = pd.read_html(html)[0].iloc[[0,2],1]
ValueError: No tables found
我想有一个条件来跳过没有表格的网页,以避免错误。
答案 0 :(得分:0)
Maybe this will help?您可以检查由此返回的值是否为真/伪造:
if driver.find_element_by_css_selector("table"):
# rest of your code here
有些事情吗?