使用来自https://www.mubasher.info/countries/eg/stock-prices的HTML,我试图从HTML中的表的raw中得到公司的股票价格和它的值
我在python3.7中尝试了以下代码
from urllib.request import urlopen as uReq
from bs4 import BeautifulSoup as bs
import re
quotes_page = 'https://www.mubasher.info/countries/eg/stock-prices'
uClient = uReq(quotes_page)
page_content = uClient.read()
uClient.close()
soup = bs(page_content, 'html.parser')
table = soup.findChildren('table')[0]
rows = table.findChildren('tr')
for row in rows:
cells = row.findChildren('td')
for cell in cells:
cell_content = cell.getText()
clean_content = re.sub( '\s+', ' ', cell_content).strip()
print(clean_content)
#显示以下结果,而不是页面中的实际值
{{row.name | limitTo : 20}}
{{row.value}}
{{row.changePercentage}}
{{row.change}}
{{row.turnover}}
{{row.volume}}
{{row.open}}
{{row.high}}
{{row.low}}
数据/表格是动态的。它是在最初的请求之后呈现的。有一个API,您可以直接找到源代码:
您可以通过在呈现页面时“检查”页面并找到适当的XHR来找到它:
输出:
相关问题 更多 >
编程相关推荐