http 代理和 https 代理的区别

2019-08-21 11:15:33 +08:00
 littlecowherd

** 验证函数 **

import requests
from bs4 import BeautifulSoup


def validate(proxies):
    https_url = 'https://ip.cn'
    http_url = 'http://ip111.cn/'
    headers = {'User-Agent': 'curl/7.29.0'}
    https_r = requests.get( https_url, headers=headers, proxies=proxies, timeout=10)
    http_r = requests.get( http_url, headers=headers, proxies=proxies, timeout=10)
    soup = BeautifulSoup( http_r.content, 'html.parser')
    result = soup.find(class_='card-body').get_text().strip().split('''\n''')[0]

    print(f"当前使用代理:{proxies.values()}")
    print(f"访问 https 网站使用代理:{https_r.json()}")
    print(f"访问 http 网站使用代理:{result}")

** 测试 **

3103 次点击
所在节点    问与答
4 条回复
ysc3839
2019-08-21 11:58:00 +08:00
你这不是“ http 代理和 https 代理”,而是“访问 http/https 网站时使用的代理”。
http/https 代理指的是客户端连接代理服务器的协议。
littlecowherd
2019-08-21 17:48:00 +08:00
emmm,我现在的理解是:
proxies 字典里的 key 的表示协议类型( http/https )应该使用哪个代理服务器(对应的 value ),当找不到对应的协议的时候就默认不使用。
http/https 代理指的是 key 对应的值(即代理地址)的协议,如
proxies = {
'https': 'https://222.189.244.56:48304'
}
中的 https://222.189.244.56:48304。( https 代理)

不知道我的理解对不对?
littlecowherd
2019-08-21 17:49:14 +08:00
@ysc3839
emmm,我现在的理解是:
proxies 字典里的 key 的表示协议类型( http/https )应该使用哪个代理服务器(对应的 value ),当找不到对应的协议的时候就默认不使用。
http/https 代理指的是 key 对应的值(即代理地址)的协议,如
proxies = {
'https': 'https://222.189.244.56:48304'
}
中的 https://222.189.244.56:48304。( https 代理)

不知道我的理解对不对?
ysc3839
2019-08-21 18:09:48 +08:00
@littlecowherd 是的。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/593765

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX