我已经编写了我的第一个python代码,以从网络上抓取股息历史记录表,但是soup.select语句似乎没有选择任何内容,并导致了索引错误。
请问如何解决的任何建议?
from selenium import webdriver
from bs4 import BeautifulSoup
import pandas as pd
driver = webdriver.Chrome(executable_path='F:\PythonApps\ChromeDriver\ChromeDriver.exe')
driver.get("https://www.dividendchannel.com/history/?symbol=ibm")
soup = BeautifulSoup(driver.page_source,"lxml")
driver.quit()
table = soup.select("table#Dividend History")[0]
print(table)
list_row =[[tab_d.text.strip().replace("\n","") for tab_d in
item.select('th,td')] for item in table.select('tr')]
for data in list_row[:2]:
print(' '.join(data))
文件“F:/System/Python/dividend.py”,第 9 行,在 table = soup.select("table#Dividend History")[0]
IndexError:列表索引超出范围
相关分类