爬虫代理服务器

免费代理网站:

https://www.xicidaili.com/

使用了几个代理不太管用,最后使用这个爬到了:

proxy_addr = “163.125.251.172:8088”

代码段如下–百度好像这样爬不到内容,data的长度很短,优快云博客首页就可以。

import urllib.request
import urllib.error
def user_proxy(url,proxy_addr):
    proxy = urllib.request.ProxyHandler({"http":proxy_addr})
    opener = urllib.request.build_opener(proxy,urllib.request.HTTPHandler)
    # 安装为全局
    urllib.request.install_opener(opener)
    data = urllib.request.urlopen(url).read().decode("utf-8","ignore")
    return data


proxy_addr = "163.125.251.172:8088"
url = "http://baidu.com/"
url = "https://blog.youkuaiyun.com/"
try:
    data = user_proxy(url=url, proxy_addr=proxy_addr)
    print(data)
    print("--爬取成功")
except urllib.error.URLError as e:
    if hasattr(e,"code"):
        print(e.code)
    if hasattr(e,"reason"):
        print(e.reason)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值