脚本:
- import requests
- from bs4 import BeautifulSoup
-
- url = "https://q.stock.sohu.com/cn/bk_4444.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))
效果: