【爬虫】模拟百度搜索,爬取搜索界面源代码

import urllib.request
import urllib.parse
get_data={'wd':'中国'}
get_data_encode=urllib.parse.urlencode(get_data)
request_url='http://www.baidu.com/s'
request_url+='?'+get_data_encode
print(request_url)
response=urllib.request.urlopen(request_url)
page_sourse=response.read()
with open('baidu.html','wb') as f:
    f.write(page_sourse)
    f.close()
print(page_sourse.decode('utf-8./'))

打开保存的页面:
这里写图片描述

猜你喜欢

转载自blog.csdn.net/weixin_38052444/article/details/82663904
今日推荐