Often go to Webmaster tools to find the IP of a domain name, and then locate the location of the IP, where, such as which province operators, Python can do a good job, mainly using the URLLIB2 and re modules
The following code is directly affixed:
Import Urllib2
Import re
Url= "ip.chinaz/? ip=211.152.42.6 "
Res=urllib2.urlopen (URL)
Msg=res.read ()
#此处一定要使用Unicode编码
Find_text=u "Query Results"
#因为网页内容为默认的utf-8 encoding, so it needs to be converted to utf-8 encoding to correctly match
Doc=re.search (' \<strong class= ' red ' \> ' +find_text.encode (' utf-8 ') + ' .*\</strong\> ', msg)
If Doc:
Result=doc.group ()
Print Result.decode (' Utf-8 ')
The results are as follows:
in [+]: Print Result.decode (' Utf-8 ')
<strong class= "Red" > Results [1]: 211.152.42.6 ==>> 3549964806 ==>> Shanghai Beijing century internet Broadband data center Telecom node </strong>
Using native Python is handy, of course, if you have beautifulsoup you can use it directly.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Python character encoding processing to find an IP location