东方财富MCP
MCP 服务配置
复制以下 JSON 到 OPClaw 或其他 MCP 客户端的配置文件中即可使用
{
"mcpServers": {
"eastmoney-mcp": {
"args": [
"string"
]
}
}
}
服务介绍
east money data by spyder
介绍
本指南将向您展示如何使用spyder从东方财富网(East Money)抓取数据。spyder是一个强大的Python库,用于网页抓取和数据提取。
安装依赖
首先,确保您的环境中已安装了requests和beautifulsoup4。如果未安装,可以通过以下命令进行安装:
bash
pip install requests beautifulsoup4
编写代码
接下来,我们将编写一个简单的脚本来获取东方财富网上某只股票的数据。这里以获取贵州茅台(股票代码:600519)的历史交易数据为例。
导入库
python
import requests
from bs4 import BeautifulSoup
获取网页内容
定义一个函数来请求网页并解析HTML内容。
python
def get_html(url):
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)
if response.status_code == 200:
return response.text
else:
return None
解析数据
使用BeautifulSoup解析返回的HTML文档,并从中提取所需的信息。
python
def parse_data(html):
soup = BeautifulSoup(html, 'lxml')
table = soup.find('table', attrs={'class': 'history_table'})
rows = table.find_all('tr')[1:] # 跳过表头
for row in rows:
cols = row.find_all('td')
date = cols[0].get_text().strip()
open_price = cols[1].get_text().strip()
high = cols[2].get_text().strip()
low = cols[3].get_text().strip()
close = cols[4].get_text().strip()
volume = cols[5].get_text().strip()
print(f"日期: {date}, 开盘价: {open_price}, 最高价: {high}, 最低价: {low}, 收盘价: {close}, 成交量: {volume}")
主函数
最后,定义主函数来调用上述两个函数。
python
def main():
url = "http://quote.eastmoney.com/concept/sz000858.html"
html = get_html(url)
if html:
parse_data(html)
if name == "main":
main()
请注意,实际应用中可能需要根据目标网站的具体结构调整选择器等细节。此外,频繁爬取可能会对服务器造成负担,请合理控制访问频率,并遵守相关法律法规及网站的使用条款。
更多关于spyder的信息可以参考其官方文档。对于更复杂的爬虫需求,建议学习使用Scrapy框架。