【发布时间】:2021-10-23 00:28:34
【问题描述】:
我正在尝试从 finivz 中提取数据,但我始终只能提取一行。 这是我的代码:
url = ('https://finviz.com/quote.ashx?t=' + ticker.upper())
r = Request(url, headers = header)
html = urlopen(r).read()
soup = BeautifulSoup(html, 'lxml')
rows = soup.find_all('tr')
rows = rows[13:20]
for row in rows:
row_td = row.find_all('td') <------------ I believe the issue is with this section?
#print(row_td)
str_cells = str(row_td)
clean = BeautifulSoup(str_cells, "lxml").get_text()
print(clean)
仅打印:
[股息 %, 2.97%, 速动比率, 1.30, 过去 5 年的销售额, -5.70%, 毛利率, 60.60%, 52W Low, 20.59%, ATR, 0.64] - 即使我指定rows[13:30]
我想打印出表 on the page. 中的所有行 here is a screenshot of the table
【问题讨论】:
-
将使用
row_td的代码放入循环中。循环完成后,它只有最后一个值。
标签: python beautifulsoup html-table finance