#获取网页中2019会计师事务所100强榜单
import pandas as pd
data=pd.DataFrame()
url_list=['https://www.cnpp.cn/focus/33661.html']
for url in url_list:
data=data.append(pd.read_html(url))
pd.set_option('display.unicode.east_asian_width',True)
data.to_excel('2022百强所.xlsx',index=False,header=None)
在学习运行这段代码时发现FutureWarning的警告,未来frame.append将不再使用
但该代码最终的目的是将网站的内容写入excel,可以直接写为
import pandas as pd
url='https://www.cnpp.cn/focus/33661.html'
data=pd.read_html(url)[0]
data.to_excel('2022百强所.xlsx',index=False,header=None)
需要注意的地方:
#返回的是DataFrame
data=pd.read_html(url)[0]
#返回的是list
#list不能写入excel,会报错AttributeError: 'list' object has no attribute 'to_excel'
data=pd.read_html(url)