【Day4】4.Request对象之Get请求与URL编码
import urllib.parse as up import urllib.request as ur kw = '动漫' data ={ 'kw':kw, 'ie':'utf-8', 'pn':100 } data_url = up.urlencode( data ) ret = up.unquote(data_url) request = ur.Request('https://tieba.baidu.com/f?'+data_url) response = ur.urlopen(request).read() with open('%s.html' % kw,'wb') as f: f.write(response)