Python简单获取自身外网IP的方法 本文实例讲述了Python简单获取自身外网IP的方法。分享给大家供大家参考,具体如下: #encoding=utf-8 #author: walker #date: 2016-03-07 #function: 获取自己的外网IP import requests from bs4 import BeautifulSoup #获取外网IP def GetOuterIP(): url = r'http://www.whereismyip.com/' r = requests.get(url) bTag = BeautifulSoup(r.text, 'html.parser', from_encoding='utf-8').find('b') ip = ''.join(bTag.stripped_strings) print('ip:' + ip) if __name__ == '__main__': GetOuterIP() 更多关于Python相关内容感兴趣的读者可查看本站专题:《Python URL操作技巧总结》、《Python图片操作技巧总结》、《Python数据结构与算法教程》、《Python Socket编程技巧总结》、《Python函数使用技巧总结》、《Python字符串操作技巧汇总》、《Python入门与进阶经典教程》及《Python文件与目录操作技巧汇总》 希望本文所述对大家Python程序设计有所帮助。