# encoding: utf-8 import urllib.request import urllib.parse url = "https://www.so.com/s?q=" keyword = input("请输入搜索关键词") keyword = urllib.parse.quote(keyword) urlkeyword = url+keyword print(urlkeyword) response = urllib.request.urlopen(url=urlkeyword) content = response.read() print(content) html = content.decode('UTF-8') print(html) with open("360shanxijiaotong.html", "w", encoding="utf-8") as f: f.write(html)