-
Notifications
You must be signed in to change notification settings - Fork 0
/
bikesearch.py
executable file
·210 lines (159 loc) · 5.95 KB
/
bikesearch.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
#!/usr/bin/env python
# coding=utf8
import cgitb
import urllib2
import httplib
import ssl
import re
import sys
from lxml import html
#print sys.argv[1]
bikesearch = sys.argv[1]
print "Search for: " + bikesearch + "<hr>"
#sslsock=httplib.HTTPSConnection("www.cyklobazar.cz")
#sslsock.request("GET", "/kola?q=mrazek")
#response = sslsock.getresponse()
#htmlSource = response.read()
#print htmlSource
def sOpen(url,search):
sslsock=httplib.HTTPSConnection(url)
sslsock.request("GET", "/"+search)
response = sslsock.getresponse()
htmlSource = response.read()
return htmlSource
def cOpen(url):
sock=urllib2.urlopen(url)
htmlSource = sock.read()
sock.close()
return htmlSource
def dolekop():
url=("http://dolekop.com/bazar?typ=1&kategorie=&lokalita=0&prumer=0&velikost=0&rok=0&cenaod=&cenado=&stari=&slovo=" + bikesearch + "&razeni=datumsestupne")
try:
sock=urllib2.urlopen(url)
sock.headers.getparam('charset')
htmlSource = sock.read()
sock.close()
# htmlISO = htmlSource.decode('ISO-8859-2')
# htmlUTF = htmlISO.encode('UTF-8')
startBazar = '</form><h2>Nalezené'
endBazar = '<div data-sticky_column="" class="sidebar">'
dolekopbazar = htmlSource.split(startBazar)[1].split(endBazar)[0]
dolekopSource = re.sub('=\"/','=\"http://dolekop.com/', dolekopbazar)
print "Dolekop.com:<br>"
print dolekopSource
print "<hr>"
except:
print "Inzerat neexistuje, alebo error na dolekop.com"
def cyklobazar():
# url=("www.cyklobazar.cz/kola?q=" + bikesearch +"")
url=("www.cyklobazar.cz")
search=("kola?q="+bikesearch)
try:
htmlS = sOpen(url,search)
startBazar = '<div class="page-header">'
# endBazar = '<div class="col-right">'
endBazar = '<div class="box-smile box-smile--right">'
cyklobazar = htmlS.split(startBazar)[1].split(endBazar)[0]
cykloSource = re.sub('=\"/','=\"https://www.cyklobazar.cz/', cyklobazar)
cykloS = re.sub('url\(','url\(www\\.cyklobazar\\.cz', cykloSource)
cykloI = re.sub('data-cfsrc','><img src', cykloS)
cykloV = re.sub('style="display:none;visibility:hidden;"','', cykloI)
print "Cyklobazar.cz:<br>"
print cykloV
print "<hr>"
except:
print "Inzerat neexistuje, alebo error na cyklobazar.cz"
def bazoscz():
url=("http://sport.bazos.cz/horska/?hledat=" + bikesearch + "&rubriky=sport&hlokalita=&humkreis=25&cenaod=&cenado=&Submit=Hledat&kitx=ano")
try:
htmlS = cOpen(url)
startBazar = 'class="listainzerat"'
endBazar = '<div align="left">©'
bazoscz = htmlS.split(startBazar)[1].split(endBazar)[0]
bazosSource = re.sub('=\"/','=\"http://sport.bazos.cz/', bazoscz)
print "bazos.cz:<br>"
print bazosSource
print "<hr>"
except:
print "Inzerat neexistuje, alebo error na bazos.cz"
def bazossk():
url=("http://sport.bazos.sk/horska/?hledat=" + bikesearch + "&rubriky=sport&hlokalita=&humkreis=25&cenaod=&cenado=&Submit=H%C4%BEada%C5%A5&kitx=ano")
try:
htmlS = cOpen(url)
startBazar = 'class="listainzerat"'
endBazar = '<div align="left">©'
bazossk = htmlS.split(startBazar)[1].split(endBazar)[0]
bazosskSource = re.sub('=\"/','=\"http://sport.bazos.sk/', bazossk)
print "bazos.sk:<br>"
print bazosskSource
print "<hr>"
except:
print "Inzerat neexistuje, alebo error na bazos.sk"
def mtbiker():
url=("http://www.mtbiker.sk/bazar?kat=all&okres=&typ_predaj=1&typ_kupa=1&order=time&s=" + bikesearch + "&f_category_id=&cena_od=&cena_do=&user_id=0")
try:
htmlS = cOpen(url)
# startBazar = '<div class=\'bazar_row\'>'
startBazar = '<button class="btn" data-dismiss="modal" aria-hidden="true">OK</button>'
# endBazar = '<footer>'
endBazar = '©'
mtbiker = htmlS.split(startBazar)[1].split(endBazar)[0]
mtbikerSource = re.sub('=\"/','=\"http://mtbiker.sk/', mtbiker)
mtbikerSource = re.sub('=\'/','=\'http://mtbiker.sk/', mtbikerSource)
print "mtbiker.sk:<br>"
print mtbikerSource
print "<hr>"
except:
print "Inzerat neexistuje, alebo error na mtbiker"
def sbazar():
url=("http://www.sbazar.cz/hledej/" + bikesearch + "/628-kola")
try:
htmlS = cOpen(url)
startBazar = '<div id="mrEggsResults">'
endBazar = '<div id="skyStopper">'
sbazar = htmlS.split(startBazar)[1].split(endBazar)[0]
sbazarSource = re.sub('href=\"/','href=\"http://www.sbazar.cz/', sbazar)
sbazarSource = re.sub('data\-origin=\"/','><img src=\"http:/', sbazarSource)
print "sbazar.cz:<br>"
print sbazarSource
print "<hr>"
except:
print "Inzerat neexistuje, alebo error na sbazar<hr>"
def kolobazar():
url=("http://www.kolobazar.cz/filtr-inzeratu.html?text=" + bikesearch + "&kategorie=&kraj=cela-cr&cena_od=&cena_do=")
try:
htmlS = cOpen(url)
startBazar = '<script type="text/javascript" src="/funkce/otevri_inzerat.js"></script>'
endBazar = '<div class="strana">'
kolobazar = htmlS.split(startBazar)[1].split(endBazar)[0]
kolobazarSource = re.sub('=\"/','=\"http://www.kolobazar.cz/', kolobazar)
kolobazarSource = re.sub('zobrazit celý text inzerátu a konta', '<br><br>------------------------------------------------<br><br>', kolobazarSource)
print "kolobazar.cz:"
print kolobazarSource
print "<hr>"
except:
print "Inzerat neexistuje, alebo error on kolobazar<hr>"
def aukrocz():
#url=("http://aukro.cz/listing/listing.php?string=" + bikesearch + "&search_scope=v%C5%A1echny+kategorie&buyUsed=1")
url=("http://aukro.cz/listing/listing.php?string=" + bikesearch + "&search_scope=category-17570&buyUsed=1")
try:
htmlS = cOpen(url)
startBazar = '<h2 class="listing-header">seznam nabídek</h2>'
endBazar = '<div class="pager pager-bottom">'
aukrocz = htmlS.split(startBazar)[1].split(endBazar)[0]
aukroczSource = re.sub('=\"/','=\"http://aukro.cz/', aukrocz)
aukroczSource = re.sub('<div class=\"photo\" data\-img=\'\[\[\"', '<img src="', aukroczSource)
aukroczSource = re.sub('\"]]\'', '">', aukroczSource)
print "aukro.cz:"
print aukroczSource
print "<hr>"
except:
print "Inzerat neexistuje, alebo error na aukro.cz <hr>"
dolekop()
cyklobazar()
bazoscz()
bazossk()
mtbiker()
sbazar()
aukrocz()
kolobazar()