def page(url, head={}, proxy={}): agent = {"User-Agent": "Mozilla/5.0 (Window 7) Chrome/72.0"} if head: head = dict(agent, **head) r = requests.get(url) if r.encoding == 'ISO-8859-1': encodes = requests.utils.get_encodings_from_content(r.text) if encodes: encode = encodes[0] else: encode = r.apparent_encoding html = r.content.decode(encode, 'replace') #如果设置为replace,则会用?取代非法字符; return html; ''' c = re.search(r'charset=["\']?([^\'"]*)', r.text) if c: r.encoding = c.group(1) ''' html = r.text return html
More 心情墙
More 和平鸽小语
Copyright@贴心博客(Imblog)
Run:2.117/22.844(ms); 6(sql)/2.103(MB); comm:info/detail; Upd:2025-01-10 21:16:50