找到返回的url
url = https://xueqiu.com/service/v5/stock/screener/quote/list?page={page}&size=30&order=desc&order_by=amount&exchange=CN&market=CN&type=sha&_=1637908787379
思路,我们利用request来请求json数据,使用pandas来解析json数据,总的来说python爬虫不难的。
import requests
import pandas as pd
# 伪装
headers = {
# 浏览器伪装
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36'
}
# 空df接收数据
financial_df = pd.DataFrame([])
for page in range(1, 56):
# 构造url
url = f'https://xueqiu.com/service/v5/stock/screener/quote/list?page={page}&size=30&order=desc&order_by=amount&exchange=CN&market=CN&type=sha&_=1637908787379'
response = requests.get(url, headers=headers)
json_data = response.json()
# 解析json数据
df = pd.DataFrame.from_dict(json_data['data']['list'])
financial_df = financial_df.append(df)
print(financial_df)
financial_df.to_excel('股票交易数据.xlsx',index=False)
不要浪费时间,加油,美好的未来。