python爬虫股票信息代码
时间: 2024-07-28 07:01:28 浏览: 160
Python爬取股票信息通常会涉及到Web scraping和数据处理。以下是一个简单的例子,展示如何使用BeautifulSoup库配合requests获取腾讯股票(Tencent)的基本信息:
```python
import requests
from bs4 import BeautifulSoup
# 定义目标网页URL
url = "https://finance.qq.com/q往上/q_hist_data.php?code=0700.HK"
# 发送GET请求
response = requests.get(url)
# 检查请求是否成功
if response.status_code == 200:
# 解析HTML内容
soup = BeautifulSoup(response.text, 'html.parser')
# 找到包含股票信息的部分(这通常是通过特定CSS选择器找到)
stock_info = soup.find('div', {'class': 'hist_data'})
# 提取你需要的信息,例如股票名称、最新价格等
stock_name = stock_info.find('span', {'class': 'stock'}).text
latest_price = stock_info.find('span', {'class': 'last'}).text
print(f"股票名称: {stock_name}, 最新价格: {latest_price}")
else:
print("请求失败")
#
阅读全文
相关推荐

















