gpt4 book ai didi

python - 从 http ://ip. zscaler.com/获取公共(public) IP 和其他基于文本的信息

转载 作者:行者123 更新时间:2023-12-01 01:20:21 32 4
gpt4 key购买 nike

通过这两个Python命令,我可以轻松获得公共(public)IP。

>>> get('https://ident.me').text
'1.2.3.4'
>>>

>>> urllib.request.urlopen('https://ident.me').read().decode('utf8')
'1.2.3.4'
>>>

但是,当我将 URL 从 https://ident.me 更改时至http://ip.zscaler.com/ ,我收到了太多不必要的 HTML 信息。

我只对以下基于文本的信息感兴趣,如下面的屏幕截图所示。

测试代理 1 Test Proxy 1

测试代理 2 enter image description here

测试代理 3 enter image description here

是否可以仅从 http://ip.zscaler.com/ 获取重要的基于文本的信息?并删除其他不必要的 HTML 标记?

所需输出

>>> get('http://ip.zscaler.com/').text
The request received from you did not have an XFF header, so you are quite likely not going through the Zscaler proxy service.
Your request is arriving at this server from the IP address x.x.x.x
Your Gateway IP Address is most likely x.x.x.x
>>>

>>> urllib.request.urlopen('http://ip.zscaler.com/').read().decode('utf8')
The request received from you did not have an XFF header, so you are quite likely not going through the Zscaler proxy service.
Your request is arriving at this server from the IP address x.x.x.x
Your Gateway IP Address is most likely x.x.x.x
>>>

最佳答案

使用BeautifulSouprequests :

from bs4 import BeautifulSoup
from requests import get

URL = "http://ip.zscaler.com/"

# GET request to url
request = get(URL).text

# Create parser
soup = BeautifulSoup(request, features="html.parser")

# Print out headline
headline = soup.find("div", attrs={"class": "headline"})
print(headline.text)

# Print out details
for detail in soup.find_all("div", attrs={"class": "details"}):
print(detail.text)

输出如下:

The request received from you did not have an XFF header, so you are quite likely not going through the Zscaler proxy service.
Your request is arriving at this server from the IP address 119.17.136.170
Your Gateway IP Address is most likely 119.17.136.170

关于python - 从 http ://ip. zscaler.com/获取公共(public) IP 和其他基于文本的信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53901391/

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