获取医疗器械板块的个股列表,用python爬虫做到(数据网址:板块 - 医疗器械概念 - 股票行情中心 - 搜狐证券)
- import requests
- from bs4 import BeautifulSoup
- # 获取医疗器械概念个股列表
-
- url = "https://q.stock.sohu.com/cn/bk_5561.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))
效果: