1. 打开https://www.baidu.com/
2. 输入ip, 进行搜索, 获取url
http://cn.bing.com/search?q=ip&go=%E6%8F%90%E4%BA%A4&qs=n&form=QBLH&pq=ip&sc=8-2&sp=-1&sk=&cvid=14b93b305cdc4183875411c3d9edf938
3. 查找url返回结果
编写python匹配正则表达式
4. Python完整代码
# -*- coding: utf-8 -*-
import urllib2
import re
__author__ = '10'
url = "http://cn.bing.com/search?q=ip&go=%E6%8F%90%E4%BA%A4&qs=n&form=QBLH&pq=ip&sc=8-2&sp=-1&sk=&cvid=14b93b305cdc4183875411c3d9edf938"
html = urllib2.urlopen(url).read()
#print html
html_re = re.compile(r'本机 ip: (.+?) 上海市 联通',re.DOTALL)
for x in html_re.findall(html):
print "Public IP:" + x
5. 运行结果