[英]Python - re.search - re.compile
我是新手,但仍在嘗試正確地進行解析。 有什么建議么。
import urllib2
import re
## Open Connection ##
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor())
oururl = opener.open('http://www.ip-lookup.net')
## IP Addresss finder ##
theIP = re.compile(r"d{1,3}.d{1,3}.d{1,3}.d{1,3}")
ip = re.search(theIP, str(oururl))
## Country finder ##
roughCountry = re.compile('([A-Z]\w+)( [A-Z]\w+){0,2}(?=\<\/a\>\s\s)')
Country = re.search(roughCountry, str(oururl))
## Print out ##
print "Your IP is:", ip
print "Your Country is:", Country
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.