Minor update

This commit is contained in:
Miroslav Stampar
2016-03-01 11:56:56 +01:00
parent 336169e181
commit 05fa7eb7c6
2 changed files with 7 additions and 4 deletions

View File

@@ -14,14 +14,17 @@
import sys
import urllib
import urllib2
TIMEOUT = 10
def get_pagerank(url):
url = url.encode('utf8') if isinstance(url, unicode) else url
_ = 'http://toolbarqueries.google.com/tbr?client=navclient-auto&features=Rank&ch=%s&q=info:%s' % (check_hash(hash_url(url)), urllib.quote(url))
try:
f = urllib.urlopen(_)
rank = f.read().strip()[9:]
except Exception:
req = urllib2.Request(_)
rank = urllib2.urlopen(req, timeout=TIMEOUT).read().strip()[9:]
except:
rank = 'N/A'
else:
rank = '0' if not rank or not rank.isdigit() else rank