zoukankan      html  css  js  c++  java
  • Python学习-20.Python的Urllib模块

    除了 Http 模块可以模拟 Http 请求外,使用 Urllib 模块也是可以模拟 Http 请求的,只不过功能相对弱一点。

    1 import urllib.request
    2 
    3 opener = urllib.request.urlopen("http://www.baidu.com")
    4 bytes = opener.read()
    5 html = bytes.decode('gbk','ignore')
    6 print(html)
    7 opener.close()

    获取百度的主页并输出到控制台上。注意的是控制台的编码是 gbk 的,而获取到的编码是 utf-8 的,因此需要在 decode 的第二个参数填上 ignore。

  • 相关阅读:
    BZOJ 1003 物流运输
    549565
    26566
    68
    554554
    5656
    49886
    5989
    6898
    656
  • 原文地址:https://www.cnblogs.com/h82258652/p/3997520.html
Copyright © 2011-2022 走看看