写一段爬取同花顺股东户数减少大于10%的代码,能够正常运行
时间: 2023-06-13 14:08:40 浏览: 55
好,以下是一份基于 Python 的爬取同花顺股东户数减少大于10%的代码:
```python
import requests
from bs4 import BeautifulSoup
url = 'http://stockpage.10jqka.com.cn/600519/holder/'
res = requests.get(url)
soup = BeautifulSoup(res.text, 'html.parser')
table = soup.find('table', {'class': 'm_table J_ajaxtable'})
rows = table.find_all('tr')
for row in rows[1:]:
cols = row.find_all('td')
name = cols[0].text.strip()
decrease = cols[-2].text.strip()
if decrease.startswith('+'):
continue
decrease = float(decrease[:-1])
if decrease >= 10:
print(name, decrease)
```
这段代码使用了 requests 库和 BeautifulSoup 库来获取股票代码为 600519 的同花顺股东信息页面,并解析出其中的表格数据。然后对于每一行数据,判断其股东户数的变化幅度是否大于等于 10%,如果满足条件则将其输出。注意,由于同花顺网页的特点,我们需要过滤掉那些户数增加的股东信息,所以代码中有一个判断语句用于跳过这些行。