gpt4 book ai didi

python - 在 Python 中解析 PAC 文件而不使用 C 模块

转载 作者:太空宇宙 更新时间:2023-11-03 18:05:57 25 4
gpt4 key购买 nike

我处于无法使用 pacparser 库的困境,我希望有人有一个纯 python 解决方案(没有 C/c++ 模块)。

我有一个返回多个代理的 PAC 文件:

function FindProxyForURL(url,host)
{
if (isPlainHostName(host))
{ return "DIRECT"; }

#// Internal network Hosts 
if (isInNet(host, "158.232.0.0", "255.255.0.0") || isInNet(host, "127.0.0.1", "255.255.255.255")|| isInNet(host, "10.0.0.0", "255.0.0.0"))
{ return "DIRECT"; }

#// Connect through proxy server for all other hosts. If proxy server is not available, connect directly
return "PROXY proxy.site.com:3128; PROXY proxy02.site.com:3128; PROXY proxy05.site.com:3128; PROXY proxy03.site.com:3128; PROXY proxy04.site.com:3128";

}

如何仅使用 python 解析此内容以及判断哪个代理已启动的最佳方法是什么?

感谢您以及您对学院的关心! :)

最佳答案

我创建了一个名为 PyPAC 的纯 Python 库这应该可以满足您的需求。它提供了 requests.Session 的子类,其中包括荣誉 PAC 并包括 PAC 自动发现。

在内部,它使用 Js2Py,一个解析和执行 JavaScript 的 Python 库。然后,PyPAC 具有 PAC 规范所需的各种 JavaScript 函数的 Python 实现。

关于python - 在 Python 中解析 PAC 文件而不使用 C 模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26911029/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com