python编码解决方案

xiaoxiao2021-02-28  12

import urllib.request def openUrl(url): req = urllib.request.Request(url) req.add_header('User-Agent',''Mozilla/5.0 (Windows NT 6.1; \ WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36'') response = urllib.request.urlopen(req) html = response.read().decode('raw_unicode_escape') return html if __name__ == '__main__': url = 'https://www.baidu.com' html = openUrl(url)重点在于编码 raw_unicode_escape
转载请注明原文地址: https://www.6miu.com/read-2650196.html

最新回复(0)