Loading

【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)
posted @ 2019-11-20 14:37  5572  阅读(298)  评论(0编辑  收藏  举报