作者:小阳阳93_967 | 来源:互联网 | 2023-07-19 14:54
Python3.5爬虫之由浅入深(三、html转excel)Python3.5爬虫之由浅入深(一、get网页)望共同进步转载请注明地址:http:blog.csdn.ne
Python3.5 爬虫之由浅入深(三、html转excel)
Python3.5 爬虫之由浅入深(一、get网页)
望共同进步
转载请注明地址:http://blog.csdn.net/weixin_39701039/article/details/79544265
这里虽然是关于html转excel,看上去好像和爬虫没有关系,但是我们再爬虫的过程中,把抓取下来的网页html等转换成excel是不是更方便以后文件的处理呢
先上代码了:
#coding:utf-8
#python3.5.1
import requests
url = 'http://tjj.lishui.gov.cn/ydkp/201712/sheet001.htm'
path = r'G:\任务20180312\test'
#定义请求头部
headers = {
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36'
}
respOnse= requests.get(url,headers = headers)
response.encoding = 'utf-8'
with open(path + '/' + '丽水市生产总值.xls','wb') as f:
f.write(response.content)
这里其实得到的是伪excel
我们来打开得到的文件,如下:
我们尝试右键选择以Notepad++打开(Notepad++是一个html辅助工具),发现可以再现代码:
具体在写入excel可能遇到一些问题可以结合 http://blog.csdn.net/weixin_39701039/article/details/79576549 来看看
望有所帮助,望采纳!