python uses HTTP tunnel proxy IP method

The method of using the HTTP tunnel proxy IP can be realized through the requests library of Python. The specific steps are as follows:

1. Import requests library and os library:

```python

import requests

import us

```

2. Set proxy IP and port number:

```python

proxy_host = 'proxy IP'

proxy_port = 'proxy port number'

```

3. Set proxy authentication information (if required):

```python

proxy_user = 'proxy user name'

proxy_pass = 'proxy password'

```

4. Set the proxy type and proxy address:

```python

proxies = {

'http': f'http://{proxy_user}:{proxy_pass}@{proxy_host}:{proxy_port}',

'https': f'https://{proxy_user}:{proxy_pass}@{proxy_host}:{proxy_port}'

}

```

5. Use a proxy when sending requests:

```python

response = requests.get(url, proxies=proxies)

```

Full code example:

```python

import requests

import us

proxy_host = 'proxy IP'

proxy_port = 'proxy port number'

proxy_user = 'proxy user name'

proxy_pass = 'proxy password'

proxies = {

'http': f'http://{proxy_user}:{proxy_pass}@{proxy_host}:{proxy_port}',

'https': f'https://{proxy_user}:{proxy_pass}@{proxy_host}:{proxy_port}'

}

response = requests.get(url, proxies=proxies)

```

Note: To use the HTTP tunnel proxy IP, you need to ensure that the proxy server supports the HTTP CONNECT method.

#! -*- encoding:utf-8 -*-

    import requests

    # 要访问的目标页面
    targetUrl = "http://ip.hahado.cn/ip"

    # 代理服务器
    proxyHost = "ip.hahado.cn"
    proxyPort = "39010"

    # 代理隧道验证信息
    proxyUser = "username"
    proxyPass = "password"

    proxyMeta = "http://%(user)s:%(pass)s@%(host)s:%(port)s" % {
        "host" : proxyHost,
        "port" : proxyPort,
        "user" : proxyUser,
        "pass" : proxyPass,
    }

    proxies = {
        "http"  : proxyMeta,
        "https" : proxyMeta,
    }

    resp = requests.get(targetUrl, proxies=proxies)

    print resp.status_code
    print resp.text

Guess you like

Origin blog.csdn.net/weixin_73725158/article/details/130765246