用requests自动访问网页,下载网页内容

import requests


# 请求下载excel
def downloading(text_path):
    # 访问要下载的链接文件
    with open(text_path) as f:
        for line in f.readlines():
            try:
                # 获取内容,生成xls
                r = requests.get(line)
                excel_name = text_path[:-5] + ".xls"
                with open(excel_name, "wb") as code:
                    code.write(r.content)
            except:
                print("地址错误无法下载")
posted @ 2018-03-26 11:56  bingo彬哥  阅读(1087)  评论(0编辑  收藏  举报
本站总访问量