How to handle response encoding from urllib.request.urlopen()

后端 未结 7 2215
一向
一向 2020-11-27 03:52

I\'m trying to search a webpage using regular expressions, but I\'m getting the following error:

TypeError: can\'t use a string pattern on a bytes-lik

7条回答
  •  Happy的楠姐
    2020-11-27 04:28

    You just need to decode the response, using the Content-Type header typically the last value. There is an example given in the tutorial too.

    output = response.decode('utf-8')
    

提交回复
热议问题