1

我想从 python 程序中找到我的公共 IP 地址。

到目前为止,这是唯一的网站

http://www.whatismyip.com/http://whatismyip.org/

这给了没有代理的ip,其余的都给了代理。

现在 .org 站点正在使用图像,第一个在许多跨度元素中写入 ip,因此我无法使用 urllib 抓取。

任何其他想法或网站,以便我可以获得我的 ip

4

2 回答 2

5

我通常使用http://httpbin.org/

import requests

ip = requests.get('http://httpbin.org/ip').json()['origin']
于 2013-07-23T06:57:42.063 回答
0

使用lxml

import urllib
import lxml.html

u = urllib.urlopen('http://www.whatismyip.com/')
html = u.read()
u.close()

root = lxml.html.fromstring(html)
print ''.join(x.text for x in root.cssselect('#greenip *'))
于 2013-07-23T06:55:25.100 回答