/
mining.py
46 lines (35 loc) · 1.02 KB
/
mining.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
#!/usr/bin/env python
import scraperwiki
import requests
import lxml.html
import time
def extract(var,entry,di):
if var in entry.text_content():
word=entry.text_content().split()
print word
index=word.index(var)+1
if len(word) > index:
while len(word) > index:
val=word[index]
index =index+1
else:
val="NULL"
#print var+val+"\n"
if val == None:
return
di[var]=val
return val
#html = requests.get("http://www.autolanka.com/Buy.asp").content
html=open('index','r')
dom = lxml.html.fromstring(html.read())
varia=["Code:","Added:","Make:","Model:","No:","Year:","Location:","Options:","Price:","Info:"]
di={}
ads={}
for entry in dom.cssselect('.BuyDataTD'):
[extract(var,entry,di) for var in varia]
if len(di)==10:
print di
#if (len(di)==10) and not(di['Code:'].replace("Code:","") in ads):
# ads[di['Code:'].replace("Code:","")]=di
#print ads
#print"\n"