-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalexagrep.py
More file actions
42 lines (33 loc) · 875 Bytes
/
alexagrep.py
File metadata and controls
42 lines (33 loc) · 875 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env python
# -*- coding: utf8 -*-
# alexagrep.py
# Ardi nooneDOTnu1ATgmailDOTcom
# GNU GPL
import sys
import urllib2
from bs4 import BeautifulSoup
from re import sub
ATTR = [
'Global ranks ',
'Local ranks ',
'Reputation ',
'Rating ',
]
def openLink(url):
_url = 'http://www.alexa.com/siteinfo/'+ url
opener = urllib2.build_opener()
opener.addheaders = [('User-agent', 'Mozilla/5.0')]
return opener.open(_url).read()
if __name__ == '__main__':
try:
url = sys.argv[1]
except:
print 'Error url'
sys.exit()
html = openLink(url)
soup = BeautifulSoup(html)
tds = soup.find('tr', {'class':'data-row1'}).findAll('td')
i=0
for td in tds:
print ATTR[i] +' => '+ sub(r'\s+', ' ', td.find('div', {'class':'data'}).text.strip())
i = i + 1