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完整代码
1 # -*- coding: utf-8 -*- 2 import urllib2 3 import re 4 __author__ = ‘10‘ 5 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" 6 html = urllib2.urlopen(url).read() 7 #print html 8 html_re = re.compile(r‘本机 ip: (.+?) 上海市 联通‘,re.DOTALL) 9 for x in html_re.findall(html): 10 print "Public IP:" + x
5. 运行结果
时间: 2024-10-14 05:09:38