通过代理ip,爬取百度信息

import urllib.request
#构建一个Handler处理器,传入一个代理ip
httpSwitch=urllib.request.ProxyHandler({"http":"120.232.175.244:80"})
#构建一个opene对象
openr=urllib.request.build_opener(httpSwitch)
req=urllib.request.Request("http://www.baidu.com/")
text=openr.open(req)
print(text.read())
posted @ 2021-02-16 00:07  名狐1993  阅读(89)  评论(0)    收藏  举报