1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
import urllib.request import urllib.parse
base_url = 'https://www.baidu.com/s?'
data = { 'wd': '周杰伦', 'sex': '男', 'location': '中国台湾省' }
new_data = urllib.parse.urlencode(data)
url = base_url + new_data
headers = { 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36 Edg/113.0.1774.57' }
request = urllib.request.Request(url=url, headers=headers)
response = urllib.request.urlopen(request)
content = response.read().decode('utf-8')
print(content)
|