#使用urllib库,将langlang2017全站网页请求并保存
#1、引入模块
from urllib import request
from urllib import error



#2、操作
#(1)创建url
base_url = "http://www.langlang2017.com/route.html"

try:
    # (2)请求url
    reponse = request.urlopen(base_url,timeout=0.02)

    # (3)读取内容
    html = reponse.read()

    # (4)转码
    html = html.decode("utf-8")
    # (5)保存
    with open("route.html", "w", encoding="utf-8") as f:
        f.write(html)

except error.URLError as e:
    print(e)

 

相关文章:

  • 2021-12-21
  • 2022-12-23
  • 2022-12-23
  • 2021-09-10
  • 2021-05-26
  • 2021-10-20
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-15
  • 2021-11-17
  • 2022-12-23
  • 2021-09-27
相关资源
相似解决方案