Home  >  Q&A  >  body text

网页爬虫 - python爬虫打印HTML问题

PHP中文网PHP中文网2741 days ago476

reply all(2)I'll reply

  • 迷茫

    迷茫2017-04-18 10:02:33

    "User-Agent": "Mozilla/5.0 (windows 6.0)"

    python3

    import urllib.request
    url = "http://www.qiushibaike.com/8hr/page/1"
    headers = {
        #"User-Agent": "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N)"
        "User-Agent": "Mozilla/5.0 (windows 6.0)"
    }
    request = urllib.request.Request(url, headers=headers)
    response = urllib.request.urlopen(request)
    c = response.read()
    h = c.decode('utf-8')
    print(h)

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-04-18 10:02:33

    python3 does not require transcoding



    I tried the following again. Just find response.decode('UTF-8'). Yes in capital letters! ! !

    reply
    0
  • Cancelreply