我们可以从网页(板块 - 上证50_ - 股票行情中心 - 搜狐证券)中获取,
然后打印出来:
import requests
from bs4 import BeautifulSoupurl = "https://q.stock.sohu.com/cn/bk_4272.shtml"
response = requests.get(url)
soup = BeautifulSoup(response.text, "html.parser")# 找到包含class为'e1'的元素
elements = soup.find_all(class_="e1")# 提取数据并剔除非数字的成员
data_list = [element.text for element in elements if element.text.isdigit()]# 打印list最终的成员
print(data_list)
# print(len(data_list))
看结果: