zoukankan      html  css  js  c++  java
  • CentOS 7 搭建 TinyProxy 代理 &&python 脚本访问

    TinyProxy

    TinyProxy 和 Squid 都是比較優秀的代理軟件

    TinyProxy比較小眾,雖然沒有Squid的功能豐富,但是小巧簡單,也能滿足普通用戶的需求。

    Squid 是一款優秀的代理軟件,有很豐富的ACL管理功能,雖然squid很強大,但配置比較繁瑣。

    1. 安裝 TinyProxy

    yum -y install tinyproxy

    2. 配置 TinyProxy

    vim /etc/tinyproxy/tinyproxy.conf
    
    修改 Port 端口,默認為 8888
    
    Port 8888
    
    註釋掉 Allow,表示允許所有人訪問代理
    
    #Allow 127.0.0.1
    
    隱藏掉Via請求頭部,去掉下面的註釋
    
    DisableViaHeader Yes
    
    更多配置項,下面是列舉一些配置文件默認的,不需要配置:
    
    PidFile "/var/run/tinyproxy/tinyproxy.pid"
    LogFile "/var/log/tinyproxy/tinyproxy.log"
    LogLevel Info
    MaxClients 100
    MinSpareServers 5
    MaxSpareServers 20
    StartServers 10

    3. 启动 TinyProxy

    systemctl start tinyproxy.service
    
    更多命令如下:
    
    systemctl restart tinyproxy.service #重啟
    systemctl stop tinyproxy.service   #停止
    systemctl status tinyproxy.service   #檢查
    systemctl enable tinyproxy.service   #開機啟動

    4.增加Python 脚本访问

    import requests
    
    
    proxy = {
        'http': 'http://101.32.00.000:8888',
        'https': 'http://101.32.00.000:8888'
    }
    
    html = requests.get("http://i.pinimg.com/originals/e2/8a/3e/e28a3e0fa51fa68c0a79578d4485b928.jpg", proxies=proxy,
                        verify=False)
    
    print(html.status_code)
    with open('/tmp/ffff.jpg', 'wb') as file:
        file.write(html.content)
  • 相关阅读:
    爬虫大作业
    熟悉常用的HDFS操作
    数据结构化和保存
    爬取全部校园新闻
    爬取校园新闻
    Google布隆过滤器
    谷歌json和对象转换
    postgresql和postgis
    json和实体类互相转换
    Linux安装docker-compose
  • 原文地址:https://www.cnblogs.com/zhaoyingjie/p/14278726.html
Copyright © 2011-2022 走看看