python3网页抓取与下载文件

淺唱寂寞╮ 提交于 2019-12-06 17:16:43

 参考https://blog.csdn.net/c406495762/article/details/58716886

1、下载整个网页

#!/usr/bin/python
#get html page from selected url
from urllib import request

if __name__ == "__main__":
    response = request.urlopen("http://app.so.com")
    html = response.read()
    html = html.decode("utf-8")
    print(html)

2、根据url,下载文件

#!/usr/bin/python3
# e.g.http://app.so.com/
#download file from selected url
import urllib.request
url="http://shouji.360tpcdn.com/180822/aa171e9134dfa23c1d22a182ecf6d50c/com.ss.android.article.video_268.apk"
downPath='..\\apks\s.apk'#include the source name,not only path,"\\"the first is the escape character
urllib.request.urlretrieve(url,downPath)

 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!