234657812 发表于 2021-7-19 22:49:03

网页返回问题

import requests
url = 'http://www.biqukan.com/1_1094/5403177.html'
headers = {
      'User-Agent': "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko)Chrome/86.0.4240.198 Safari/537.36"
    }
req = requests.get(url=url, headers=headers)
print(req.read().decode('utf-8'))


text/html;charset=utf-8

wp231957 发表于 2021-7-20 06:26:03

没有问题???

suchocolate 发表于 2021-7-20 12:06:10

requests不用decode,直接用text就可以。
import requests


url = 'http://www.biqukan.com/1_1094/5403177.html'
headers = {
      'User-Agent': "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko)Chrome/86.0.4240.198 Safari/537.36"
    }
r = requests.get(url=url, headers=headers)
print(r.text)

234657812 发表于 2021-7-20 12:38:23

suchocolate 发表于 2021-7-20 12:06
requests不用decode,直接用text就可以。

{:7_112:}
页: [1]
查看完整版本: 网页返回问题