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)
  • 相关阅读:
    java Vamei快速教程02 方法和数据成员
    java Vamei快速教程01
    二叉树
    高效通信模型之
    高效通信模型之
    线程间通信与同步
    线程
    进程
    C++面试知识点总结
    windows下UDP服务器和客户端的实现
  • 原文地址:https://www.cnblogs.com/lvchengda/p/12618023.html
Copyright © 2011-2022 走看看