简体   繁体   中英

How do I download a website using python 3?

只是一个像php中的file_get_contents这样的http获取请求,或者我输入URL并将内容获取到变量的简单内容。

Use urllib :

from urllib.request import urlopen
html = urlopen("http://www.stackoverflow.com/").read().decode('utf-8')
print(html)

Your Intention seems to be to get a static version of a Website. This can be achieved using WGET. This tool can in one command retrieve the files for a given URL. Use the -r (recursive) Parameter with care, example:

wget -erobots=off -p -H -k -E -w 1 --random-wait -r -l 1 http://your.site .

Download a working local copy of a webpage

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM