大宗交易折溢价率爬虫
时间: 2023-12-17 14:27:31 浏览: 38
根据提供的引用内容,我理解大宗交易折溢价率是指大宗交易价格与当日收盘价之间的差异。如果大宗交易价格高于当日收盘价,则折价率为负数,反之则为正数。以下是一个简单的Python爬虫示例,可以用于获取大宗交易折溢价率数据:
```python
import requests
from bs4 import BeautifulSoup
url = 'http://data.eastmoney.com/dzjy/dzjy_mrmxa.aspx'
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3'}
response = requests.get(url, headers=headers)
soup = BeautifulSoup(response.text, 'html.parser')
table = soup.find('table', {'id': 'tab1'})
rows = table.find_all('tr')
for row in rows[1:]:
cells = row.find_all('td')
name = cells[1].text
price = float(cells[2].text)
close = float(cells[3].text)
discount = (price - close) / close
print(name, discount)
```
这个爬虫使用requests和BeautifulSoup库来获取网页内容并解析HTML。它从东方财富网上获取大宗交易数据,并计算每个交易的折溢价率。你可以根据需要修改代码来获取不同的数据或将数据保存到文件中。