|
用python抓了10页
- import pandas as pd
- import requests
- from bs4 import BeautifulSoup
- df=pd.DataFrame()
- for i in range(10):
- data=[]
- url=("http://quotes.money.163.com/data/caibao/yjgl_ALL.html?reportdate=20161231&sort=symbol&order=desc&page=%d" % i )
- r=requests.get(url)
- soup=BeautifulSoup(r.content,'html.parser')
- table=soup.find('table',attrs={'id':'plate_performance'})
- rows=table.find_all('tr')
- for row in rows:
- cols=row.find_all('td')
- cols=[ele.text.strip() for ele in cols]
- data.append(cols)
- del data[0]
- df=df.append(data,ignore_index=True)
- df.columns=['序号','代码', '名称', '每股收益', '每股现金流', '主营收入', '同比增长', '净利润', '同比增长', '公告日期', '详细']
- df.to_excel('test1.xlsx',index=False)
复制代码 |
评分
-
1
查看全部评分
-
|