from urllib.request import urlopen import re text = str(urlopen("http://txt.go.sohu.com/ip/soip").read()) ip = re.findall(r'd+.d+.d+.d+',text) print(ip[0])