python3网页抓取与下载文件

 参考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)

 

你可能感兴趣的:(爬虫学习)