Python获取本机外网IP

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. 运行结果

    

转载于:https://www.cnblogs.com/anit/p/4702070.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值