python爬虫东财股东人数户数减少大于10%
时间: 2023-06-13 13:08:30 浏览: 159
您可以使用 Python 中的 requests 库和 BeautifulSoup 库来爬取东方财富网(http://data.eastmoney.com/gdhs/)上的股东人数户数数据。具体步骤如下:
1. 使用 requests 库获取页面内容:
```python
import requests
url = 'http://data.eastmoney.com/gdhs/'
response = requests.get(url)
content = response.content
```
2. 使用 BeautifulSoup 库解析页面内容:
```python
from bs4 import BeautifulSoup
soup = BeautifulSoup(content, 'html.parser')
table = soup.find('table', {'class': 'tab1'})
rows = table.find_all('tr')
```
3. 遍历表格行,获取股票代码、股票名称、股东人数、股东户数等数据:
```python
for row in rows[1:]:
cells = row.find_all('td')
code = cells[1].text.strip() # 股票代码
name = cells[2].text.strip() # 股票名称
holders = int(cells[6].text.replace(',', '')) # 股东人数
accounts = int(cells[7].text.replace(',', '')) # 股东户数
if (accounts - holders) / holders > 0.1: # 判断股东户数减少是否大于10%
print(code, name, holders, accounts)
```
这样就可以得到股东户数减少大于10%的股票代码、股票名称、股东人数和股东户数了。