-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkeyword_finder.py
52 lines (38 loc) · 1017 Bytes
/
keyword_finder.py
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
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python
from urllib2 import urlopen
from lxml import etree
from StringIO import StringIO
import os.path
import sys
from hashlib import md5
cache_dir = "/tmp/keyword_cache"
def get_page(url):
try:
os.mkdir(cache_dir)
except OSError:
pass
cache_name = cache_dir + "/" + md5(url).hexdigest()
if os.path.isfile(cache_name):
return open(cache_name, "r")
else:
response = urlopen(url)
fout = open(cache_name, "w")
fout.write(response.read())
fout.close()
fin = open(cache_name)
return fin
def main():
# Download a page
argv = sys.argv
page_url = argv[1]
#page_url = "http://www.familyfocusdental.com.au"
page = get_page(page_url)
parser = etree.HTMLParser()
tree = etree.parse(page, parser)
import pdb; pdb.set_trace()
# Look for keywords
keywords = []
# Print Keywords
print keywords
if __name__ == "__main__":
main()