zoukankan      html  css  js  c++  java
  • 使用本地shadow socks代理

    1,第一种方式
    import urllib2
    import socks
    from sockshandler import SocksiPyHandler
    
    opener = urllib2.build_opener(SocksiPyHandler(socks.SOCKS5, "127.0.0.1", 1080))
    x = opener.open("http://www.youtube.com/")
    print x.read()
    2,第二种方式
    from urllib import request
    
    proxies = {
        'https': 'https://127.0.0.1:1080',
        'http': 'http://127.0.0.1:1080'
    }
    # 需要加上headers, 否则报错: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xa0 in position 8974: invalid start byte
    
    headers = {
        'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36'
    }
    
    google_url = 'https://www.google.com'
    opener = request.build_opener(request.ProxyHandler(proxies))
    request.install_opener(opener)
    
    req = request.Request(google_url, headers=headers)
    response = request.urlopen(req)
    
    print(response.read().decode())
    3,第三种方式
    import requests
    
    response = requests.get("http://www.google.com", proxies={
        'http': 'http://127.0.0.1:1080',
        'https': 'https://127.0.0.1:1080'
    })
    
    print(response.text)
  • 相关阅读:
    Tree Recovery解题报告
    bjtuOJ1019 Robot
    bjtuOJ1137 蚂蚁爬杆
    栈的使用,rails
    重做catch the cow
    C#3.0新特性之匿名类型
    C#Lambda表达式的用法
    C#进程的使用方法详解
    C#进程管理启动和停止
    C#LINQ查询表达式用法
  • 原文地址:https://www.cnblogs.com/lvchengda/p/12618023.html
Copyright © 2011-2022 走看看