How to use find_all method in Selene

Best Python code snippet using selene_python

create_cities.py

Source:create_cities.py Github

copy

Full Screen

...20def main():21 resp = requests.get("https://hramy.ru/regions/city_reg.htm")22 soup = BeautifulSoup(resp.content, 'lxml')23 body = soup.find('div', class_='contpost')24 list = body.find_all('tr')25 p = 026 for item in list:27 p += 128 if p != 1:29 if City.objects.filter(name=item.find_all('td')[0].text).exists():30 print("гогод " + item.find_all('td')[0].text + " уже сохранён...")31 else:32 if item.find_all('td')[3].text == "Чукотский Автономный округ":33 region = Region.objects.get(name="Чукотский автономный округ")34 City.objects.create(name=item.find_all('td')[0].text, region=region)35 print("город " + item.find_all('td')[0].text + " Добавлен!")36 elif item.find_all('td')[3].text == "Ямало-Ненецкий Автономный округ":37 region = Region.objects.get(name="Ямало-Ненецкий автономный округ")38 City.objects.create(name=item.find_all('td')[0].text, region=region)39 print("город " + item.find_all('td')[0].text + " Добавлен!")40 elif item.find_all('td')[3].text == "Крым Республика":41 region = Region.objects.get(name="Республика Крым")42 City.objects.create(name=item.find_all('td')[0].text, region=region)43 print("город " + item.find_all('td')[0].text + " Добавлен!")44 elif item.find_all('td')[3].text == "Севастополь Город":45 region = Region.objects.get(name="Севастополь")46 City.objects.create(name=item.find_all('td')[0].text, region=region)47 print("город " + item.find_all('td')[0].text + " Добавлен!")48 elif item.find_all('td')[3].text == "Ярославская Область":49 region = Region.objects.get(name="Ярославская область")50 City.objects.create(name=item.find_all('td')[0].text, region=region)51 print("город " + item.find_all('td')[0].text + " Добавлен!")52 elif item.find_all('td')[3].text == "Москва Город":53 region = Region.objects.get(name="Москва")54 City.objects.create(name=item.find_all('td')[0].text, region=region)55 print("город " + item.find_all('td')[0].text + " Добавлен!")56 elif item.find_all('td')[3].text == "Санкт-Петербург Город":57 region = Region.objects.get(name="Санкт-Петербург")58 City.objects.create(name=item.find_all('td')[0].text, region=region)59 print("город " + item.find_all('td')[0].text + " Добавлен!")60 elif item.find_all('td')[3].text == "Еврейская Автономная область":61 region = Region.objects.get(name="Еврейская автономная область")62 City.objects.create(name=item.find_all('td')[0].text, region=region)63 print("город " + item.find_all('td')[0].text + " Добавлен!")64 elif item.find_all('td')[3].text == "Ненецкий Автономный округ":65 region = Region.objects.get(name="Ненецкий автономный округ")66 City.objects.create(name=item.find_all('td')[0].text, region=region)67 print("город " + item.find_all('td')[0].text + " Добавлен!")68 elif item.find_all('td')[3].text == "Ханты-Мансийский Автономный округ - Югра Автономный округ":69 region = Region.objects.get(name="Ханты-Мансийский автономный округ - Югра (Тюменская область)")70 City.objects.create(name=item.find_all('td')[0].text, region=region)71 print("город " + item.find_all('td')[0].text + " Добавлен!")72 elif item.find_all('td')[3].text == "Адыгея Республика":73 region = Region.objects.get(name="Республика Адыгея")74 City.objects.create(name=item.find_all('td')[0].text, region=region)75 print("город " + item.find_all('td')[0].text + " Добавлен!")76 elif item.find_all('td')[3].text == "Башкортостан Республика":77 region = Region.objects.get(name="Республика Башкортостан")78 City.objects.create(name=item.find_all('td')[0].text, region=region)79 print("город " + item.find_all('td')[0].text + " Добавлен!")80 elif item.find_all('td')[3].text == "Бурятия Республика":81 region = Region.objects.get(name="Республика Бурятия")82 City.objects.create(name=item.find_all('td')[0].text, region=region)83 print("город " + item.find_all('td')[0].text + " Добавлен!")84 elif item.find_all('td')[3].text == "Алтай Республика":85 region = Region.objects.get(name="Алтайский край")86 City.objects.create(name=item.find_all('td')[0].text, region=region)87 print("город " + item.find_all('td')[0].text + " Добавлен!")88 elif item.find_all('td')[3].text == "Дагестан Республика":89 region = Region.objects.get(name="Республика Дагестан")90 City.objects.create(name=item.find_all('td')[0].text, region=region)91 print("город " + item.find_all('td')[0].text + " Добавлен!")92 elif item.find_all('td')[3].text == "Ингушетия Республика":93 region = Region.objects.get(name="Республика Ингушетия")94 City.objects.create(name=item.find_all('td')[0].text, region=region)95 print("город " + item.find_all('td')[0].text + " Добавлен!")96 elif item.find_all('td')[3].text == "Кабардино-Балкарская Республика":97 region = Region.objects.get(name="Кабардино-Балкарская Республика")98 City.objects.create(name=item.find_all('td')[0].text, region=region)99 print("город " + item.find_all('td')[0].text + " Добавлен!")100 elif item.find_all('td')[3].text == "Калмыкия Республика":101 region = Region.objects.get(name="Республика Калмыкия")102 City.objects.create(name=item.find_all('td')[0].text, region=region)103 print("город " + item.find_all('td')[0].text + " Добавлен!")104 elif item.find_all('td')[3].text == "Карачаево-Черкесская Республика":105 region = Region.objects.get(name="Карачаево-Черкесская Республика")106 City.objects.create(name=item.find_all('td')[0].text, region=region)107 print("город " + item.find_all('td')[0].text + " Добавлен!")108 elif item.find_all('td')[3].text == "Карелия Республика":109 region = Region.objects.get(name="Республика Карелия")110 City.objects.create(name=item.find_all('td')[0].text, region=region)111 print("город " + item.find_all('td')[0].text + " Добавлен!")112 elif item.find_all('td')[3].text == "Коми Республика":113 region = Region.objects.get(name="Республика Коми")114 City.objects.create(name=item.find_all('td')[0].text, region=region)115 print("город " + item.find_all('td')[0].text + " Добавлен!")116 elif item.find_all('td')[3].text == "Марий Эл Республика":117 region = Region.objects.get(name="Республика Марий Эл")118 City.objects.create(name=item.find_all('td')[0].text, region=region)119 print("город " + item.find_all('td')[0].text + " Добавлен!")120 elif item.find_all('td')[3].text == "Мордовия Республика":121 region = Region.objects.get(name="Республика Мордовия")122 City.objects.create(name=item.find_all('td')[0].text, region=region)123 print("город " + item.find_all('td')[0].text + " Добавлен!")124 elif item.find_all('td')[3].text == "Саха /Якутия/ Республика":125 region = Region.objects.get(name="Республика Саха (Якутия)")126 City.objects.create(name=item.find_all('td')[0].text, region=region)127 print("город " + item.find_all('td')[0].text + " Добавлен!")128 elif item.find_all('td')[3].text == "Северная Осетия - Алания Республика":129 region = Region.objects.get(name="Республика Северная Осетия - Алания")130 City.objects.create(name=item.find_all('td')[0].text, region=region)131 print("город " + item.find_all('td')[0].text + " Добавлен!")132 elif item.find_all('td')[3].text == "Москва Город":133 region = Region.objects.get(name="Москва")134 City.objects.create(name=item.find_all('td')[0].text, region=region)135 print("город " + item.find_all('td')[0].text + " Добавлен!")136 elif item.find_all('td')[3].text == "Татарстан Республика":137 region = Region.objects.get(name="Республика Татарстан")138 City.objects.create(name=item.find_all('td')[0].text, region=region)139 print("город " + item.find_all('td')[0].text + " Добавлен!")140 elif item.find_all('td')[3].text == "Тыва Республика":141 region = Region.objects.get(name="Республика Тыва")142 City.objects.create(name=item.find_all('td')[0].text, region=region)143 print("город " + item.find_all('td')[0].text + " Добавлен!")144 elif item.find_all('td')[3].text == "Удмуртская Республика":145 region = Region.objects.get(name="Удмуртская Республика (Удмуртия)")146 City.objects.create(name=item.find_all('td')[0].text, region=region)147 print("город " + item.find_all('td')[0].text + " Добавлен!")148 elif item.find_all('td')[3].text == "Хакасия Республика":149 region = Region.objects.get(name="Республика Хакасия")150 City.objects.create(name=item.find_all('td')[0].text, region=region)151 print("город " + item.find_all('td')[0].text + " Добавлен!")152 elif item.find_all('td')[3].text == "Чеченская Республика":153 region = Region.objects.get(name="Чеченская Республика")154 City.objects.create(name=item.find_all('td')[0].text, region=region)155 print("город " + item.find_all('td')[0].text + " Добавлен!")156 elif item.find_all('td')[3].text == "Чувашская Республика - Чувашия":157 region = Region.objects.get(name="Чувашская Республика - Чувашия")158 City.objects.create(name=item.find_all('td')[0].text, region=region)159 print("город " + item.find_all('td')[0].text + " Добавлен!")160 elif item.find_all('td')[3].text == "Алтайский Край":161 region = Region.objects.get(name="Алтайский край")162 City.objects.create(name=item.find_all('td')[0].text, region=region)163 print("город " + item.find_all('td')[0].text + " Добавлен!")164 elif item.find_all('td')[3].text == "Краснодарский Край":165 region = Region.objects.get(name="Краснодарский край")166 City.objects.create(name=item.find_all('td')[0].text, region=region)167 print("город " + item.find_all('td')[0].text + " Добавлен!")168 elif item.find_all('td')[3].text == "Красноярский Край":169 region = Region.objects.get(name="Красноярский край")170 City.objects.create(name=item.find_all('td')[0].text, region=region)171 print("город " + item.find_all('td')[0].text + " Добавлен!")172 elif item.find_all('td')[3].text == "Приморский Край":173 region = Region.objects.get(name="Приморский край")174 City.objects.create(name=item.find_all('td')[0].text, region=region)175 print("город " + item.find_all('td')[0].text + " Добавлен!")176 elif item.find_all('td')[3].text == "Ставропольский Край":177 region = Region.objects.get(name="Ставропольский край")178 City.objects.create(name=item.find_all('td')[0].text, region=region)179 print("город " + item.find_all('td')[0].text + " Добавлен!")180 elif item.find_all('td')[3].text == "Хабаровский Край":181 region = Region.objects.get(name="Хабаровский край")182 City.objects.create(name=item.find_all('td')[0].text, region=region)183 print("город " + item.find_all('td')[0].text + " Добавлен!")184 elif item.find_all('td')[3].text == "Амурская Область":185 region = Region.objects.get(name="Амурская область")186 City.objects.create(name=item.find_all('td')[0].text, region=region)187 print("город " + item.find_all('td')[0].text + " Добавлен!")188 elif item.find_all('td')[3].text == "Архангельская Область":189 region = Region.objects.get(name="Архангельская область")190 City.objects.create(name=item.find_all('td')[0].text, region=region)191 print("город " + item.find_all('td')[0].text + " Добавлен!")192 elif item.find_all('td')[3].text == "Белгородская Область":193 region = Region.objects.get(name="Белгородская область")194 City.objects.create(name=item.find_all('td')[0].text, region=region)195 print("город " + item.find_all('td')[0].text + " Добавлен!")196 elif item.find_all('td')[3].text == "Брянская Область":197 region = Region.objects.get(name="Брянская область")198 City.objects.create(name=item.find_all('td')[0].text, region=region)199 print("город " + item.find_all('td')[0].text + " Добавлен!")200 elif item.find_all('td')[3].text == "Владимирская Область":201 region = Region.objects.get(name="Владимирская область")202 City.objects.create(name=item.find_all('td')[0].text, region=region)203 print("город " + item.find_all('td')[0].text + " Добавлен!")204 elif item.find_all('td')[3].text == "Волгоградская Область":205 region = Region.objects.get(name="Волгоградская область")206 City.objects.create(name=item.find_all('td')[0].text, region=region)207 print("город " + item.find_all('td')[0].text + " Добавлен!")208 elif item.find_all('td')[3].text == "Вологодская Область":209 region = Region.objects.get(name="Вологодская область")210 City.objects.create(name=item.find_all('td')[0].text, region=region)211 print("город " + item.find_all('td')[0].text + " Добавлен!")212 elif item.find_all('td')[3].text == "Воронежская Область":213 region = Region.objects.get(name="Воронежская область")214 City.objects.create(name=item.find_all('td')[0].text, region=region)215 print("город " + item.find_all('td')[0].text + " Добавлен!")216 elif item.find_all('td')[3].text == "Ивановская Область":217 region = Region.objects.get(name="Ивановская область")218 City.objects.create(name=item.find_all('td')[0].text, region=region)219 print("город " + item.find_all('td')[0].text + " Добавлен!")220 elif item.find_all('td')[3].text == "Иркутская Область":221 region = Region.objects.get(name="Иркутская область")222 City.objects.create(name=item.find_all('td')[0].text, region=region)223 print("город " + item.find_all('td')[0].text + " Добавлен!")224 elif item.find_all('td')[3].text == "Калининградская Область":225 region = Region.objects.get(name="Калининградская область")226 City.objects.create(name=item.find_all('td')[0].text, region=region)227 print("город " + item.find_all('td')[0].text + " Добавлен!")228 elif item.find_all('td')[3].text == "Калужская Область":229 region = Region.objects.get(name="Калужская область")230 City.objects.create(name=item.find_all('td')[0].text, region=region)231 print("город " + item.find_all('td')[0].text + " Добавлен!")232 elif item.find_all('td')[3].text == "Камчатский Край":233 region = Region.objects.get(name="Камчатский край")234 City.objects.create(name=item.find_all('td')[0].text, region=region)235 print("город " + item.find_all('td')[0].text + " Добавлен!")236 elif item.find_all('td')[3].text == "Кемеровская Область":237 region = Region.objects.get(name="Кемеровская область")238 City.objects.create(name=item.find_all('td')[0].text, region=region)239 print("город " + item.find_all('td')[0].text + " Добавлен!")240 elif item.find_all('td')[3].text == "Кировская Область":241 region = Region.objects.get(name="Кировская область")242 City.objects.create(name=item.find_all('td')[0].text, region=region)243 print("город " + item.find_all('td')[0].text + " Добавлен!")244 elif item.find_all('td')[3].text == "Костромская Область":245 region = Region.objects.get(name="Костромская область")246 City.objects.create(name=item.find_all('td')[0].text, region=region)247 print("город " + item.find_all('td')[0].text + " Добавлен!")248 elif item.find_all('td')[3].text == "Курганская Область":249 region = Region.objects.get(name="Курганская область")250 City.objects.create(name=item.find_all('td')[0].text, region=region)251 print("город " + item.find_all('td')[0].text + " Добавлен!")252 elif item.find_all('td')[3].text == "Курская Область":253 region = Region.objects.get(name="Курская область")254 City.objects.create(name=item.find_all('td')[0].text, region=region)255 print("город " + item.find_all('td')[0].text + " Добавлен!")256 elif item.find_all('td')[3].text == "Ленинградская Область":257 region = Region.objects.get(name="Ленинградская область")258 City.objects.create(name=item.find_all('td')[0].text, region=region)259 print("город " + item.find_all('td')[0].text + " Добавлен!")260 elif item.find_all('td')[3].text == "Липецкая Область":261 region = Region.objects.get(name="Липецкая область")262 City.objects.create(name=item.find_all('td')[0].text, region=region)263 print("город " + item.find_all('td')[0].text + " Добавлен!")264 elif item.find_all('td')[3].text == "Магаданская Область":265 region = Region.objects.get(name="Магаданская область")266 City.objects.create(name=item.find_all('td')[0].text, region=region)267 print("город " + item.find_all('td')[0].text + " Добавлен!")268 elif item.find_all('td')[3].text == "Московская Область":269 region = Region.objects.get(name="Московская область")270 City.objects.create(name=item.find_all('td')[0].text, region=region)271 print("город " + item.find_all('td')[0].text + " Добавлен!")272 elif item.find_all('td')[3].text == "Мурманская Область":273 region = Region.objects.get(name="Мурманская область")274 City.objects.create(name=item.find_all('td')[0].text, region=region)275 print("город " + item.find_all('td')[0].text + " Добавлен!")276 elif item.find_all('td')[3].text == "Нижегородская Область":277 region = Region.objects.get(name="Нижегородская область")278 City.objects.create(name=item.find_all('td')[0].text, region=region)279 print("город " + item.find_all('td')[0].text + " Добавлен!")280 elif item.find_all('td')[3].text == "Новгородская Область":281 region = Region.objects.get(name="Новгородская область")282 City.objects.create(name=item.find_all('td')[0].text, region=region)283 print("город " + item.find_all('td')[0].text + " Добавлен!")284 elif item.find_all('td')[3].text == "Новосибирская Область":285 region = Region.objects.get(name="Новосибирская область")286 City.objects.create(name=item.find_all('td')[0].text, region=region)287 print("город " + item.find_all('td')[0].text + " Добавлен!")288 elif item.find_all('td')[3].text == "Омская Область":289 region = Region.objects.get(name="Омская область")290 City.objects.create(name=item.find_all('td')[0].text, region=region)291 print("город " + item.find_all('td')[0].text + " Добавлен!")292 elif item.find_all('td')[3].text == "Оренбургская Область":293 region = Region.objects.get(name="Оренбургская область")294 City.objects.create(name=item.find_all('td')[0].text, region=region)295 print("город " + item.find_all('td')[0].text + " Добавлен!")296 elif item.find_all('td')[3].text == "Орловская Область":297 region = Region.objects.get(name="Орловская область")298 City.objects.create(name=item.find_all('td')[0].text, region=region)299 print("город " + item.find_all('td')[0].text + " Добавлен!")300 elif item.find_all('td')[3].text == "Пензенская Область":301 region = Region.objects.get(name="Пензенская область")302 City.objects.create(name=item.find_all('td')[0].text, region=region)303 print("город " + item.find_all('td')[0].text + " Добавлен!")304 elif item.find_all('td')[3].text == "Пермский Край":305 region = Region.objects.get(name="Пермский край")306 City.objects.create(name=item.find_all('td')[0].text, region=region)307 print("город " + item.find_all('td')[0].text + " Добавлен!")308 elif item.find_all('td')[3].text == "Псковская Область":309 region = Region.objects.get(name="Псковская область")310 City.objects.create(name=item.find_all('td')[0].text, region=region)311 print("город " + item.find_all('td')[0].text + " Добавлен!")312 elif item.find_all('td')[3].text == "Ростовская Область":313 region = Region.objects.get(name="Ростовская область")314 City.objects.create(name=item.find_all('td')[0].text, region=region)315 print("город " + item.find_all('td')[0].text + " Добавлен!")316 elif item.find_all('td')[3].text == "Рязанская Область":317 region = Region.objects.get(name="Рязанская область")318 City.objects.create(name=item.find_all('td')[0].text, region=region)319 print("город " + item.find_all('td')[0].text + " Добавлен!")320 elif item.find_all('td')[3].text == "Самарская Область":321 region = Region.objects.get(name="Самарская область")322 City.objects.create(name=item.find_all('td')[0].text, region=region)323 print("город " + item.find_all('td')[0].text + " Добавлен!")324 elif item.find_all('td')[3].text == "Саратовская Область":325 region = Region.objects.get(name="Саратовская область")326 City.objects.create(name=item.find_all('td')[0].text, region=region)327 print("город " + item.find_all('td')[0].text + " Добавлен!")328 elif item.find_all('td')[3].text == "Сахалинская Область":329 region = Region.objects.get(name="Сахалинская область")330 City.objects.create(name=item.find_all('td')[0].text, region=region)331 print("город " + item.find_all('td')[0].text + " Добавлен!")332 elif item.find_all('td')[3].text == "Свердловская Область":333 region = Region.objects.get(name="Свердловская область")334 City.objects.create(name=item.find_all('td')[0].text, region=region)335 print("город " + item.find_all('td')[0].text + " Добавлен!")336 elif item.find_all('td')[3].text == "Смоленская Область":337 region = Region.objects.get(name="Смоленская область")338 City.objects.create(name=item.find_all('td')[0].text, region=region)339 print("город " + item.find_all('td')[0].text + " Добавлен!")340 elif item.find_all('td')[3].text == "Тамбовская Область":341 region = Region.objects.get(name="Тамбовская область")342 City.objects.create(name=item.find_all('td')[0].text, region=region)343 print("город " + item.find_all('td')[0].text + " Добавлен!")344 elif item.find_all('td')[3].text == "Тверская Область":345 region = Region.objects.get(name="Тверская область")346 City.objects.create(name=item.find_all('td')[0].text, region=region)347 print("город " + item.find_all('td')[0].text + " Добавлен!")348 elif item.find_all('td')[3].text == "Томская Область":349 region = Region.objects.get(name="Томская область")350 City.objects.create(name=item.find_all('td')[0].text, region=region)351 print("город " + item.find_all('td')[0].text + " Добавлен!")352 elif item.find_all('td')[3].text == "Тульская Область":353 region = Region.objects.get(name="Тульская область")354 City.objects.create(name=item.find_all('td')[0].text, region=region)355 print("город " + item.find_all('td')[0].text + " Добавлен!")356 elif item.find_all('td')[3].text == "Тюменская Область":357 region = Region.objects.get(name="Тюменская область")358 City.objects.create(name=item.find_all('td')[0].text, region=region)359 print("город " + item.find_all('td')[0].text + " Добавлен!")360 elif item.find_all('td')[3].text == "Ульяновская Область":361 region = Region.objects.get(name="Ульяновская область")362 City.objects.create(name=item.find_all('td')[0].text, region=region)363 print("город " + item.find_all('td')[0].text + " Добавлен!")364 elif item.find_all('td')[3].text == "Челябинская Область":365 region = Region.objects.get(name="Челябинская область")366 City.objects.create(name=item.find_all('td')[0].text, region=region)367 print("город " + item.find_all('td')[0].text + " Добавлен!")368 elif item.find_all('td')[3].text == "Забайкальский Край":369 region = Region.objects.get(name="Забайкальский край")370 City.objects.create(name=item.find_all('td')[0].text, region=region)371 print("город " + item.find_all('td')[0].text + " Добавлен!")372 elif item.find_all('td')[3].text == "Ярославская Область":373 region = Region.objects.get(name="Ярославская область")374 City.objects.create(name=item.find_all('td')[0].text, region=region)375 print("город " + item.find_all('td')[0].text + " Добавлен!")376if __name__ == '__main__':...

Full Screen

Full Screen

jd_spider.py

Source:jd_spider.py Github

copy

Full Screen

...24 jd_item = JDItem()25 if 'error' not in response.url:26 soup = BeautifulSoup(response.body, 'html5lib')27 is_success = 128 province_divs = soup.find_all("div", class_='j-shop-info')29 if province_divs:30 province = province_divs[0].find_all("span", class_='value')[0].string31 jd_item['province'] = province 32 else:33 jd_item['province'] = ''34 all_grades = ''35 all_rate = ''36 if soup.find_all("div", class_='total-score-view green'): #低于同行业37 all_grades = soup.find_all("p", class_='total-score-num')[0].find("span").string38 all_rate = "-" + soup.find_all("p", class_='score-des')[0].find("span", class_='percent').string39 elif soup.find_all("div", class_='total-score-view red '): #高于同行业40 all_grades = soup.find_all("p", class_='total-score-num')[0].find("span").string41 all_rate = soup.find_all("p", class_='score-des')[0].find("span", class_='percent').string42 jd_item['all_grades'] = all_grades43 jd_item['all_rate'] = all_rate44 45 goods_grades = ''46 goods_rate = ''47 if soup.find_all("div", class_='j-score')[1].find_all("div", class_='item-180 f14')[0].find("span", class_='f24 ce5393d score-180'): #高于同行业48 goods_grades = soup.find_all("div", class_='j-score')[1].find_all("div", class_='item-180 f14')[0].find("span", class_='f24 ce5393d score-180').string49 goods_rate = soup.find_all("div", class_='j-score')[1].find_all("span", class_='percent')[0].string50 elif soup.find_all("div", class_='j-score')[1].find_all("div", class_='item-180 f14')[0].find("span", class_='f24 c82c161 score-180'): #低于同行业51 goods_grades = soup.find_all("div", class_='j-score')[1].find_all("div", class_='item-180 f14')[0].find("span", class_='f24 c82c161 score-180').string52 goods_rate = '-' + soup.find_all("div", class_='j-score')[1].find_all("span", class_='percent')[0].string53 jd_item['goods_grades'] = goods_grades54 jd_item['goods_rate'] = goods_rate55 56 service_grades = ''57 service_rate = ''58 if soup.find_all("div", class_='j-score')[1].find_all("div", class_='item-180 f14')[1].find("span", class_='f24 ce5393d score-180'): #高于同行业59 service_grades = soup.find_all("div", class_='j-score')[1].find_all("div", class_='item-180 f14')[1].find("span", class_='f24 ce5393d score-180').string60 service_rate = soup.find_all("div", class_='j-score')[1].find_all("span", class_='percent')[1].string61 elif soup.find_all("div", class_='j-score')[1].find_all("div", class_='item-180 f14')[1].find("span", class_='f24 c82c161 score-180'): #低于同行业62 service_grades = soup.find_all("div", class_='j-score')[1].find_all("div", class_='item-180 f14')[1].find("span", class_='f24 c82c161 score-180').string63 service_rate = '-' + soup.find_all("div", class_='j-score')[1].find_all("span", class_='percent')[1].string64 jd_item['service_grades'] = service_grades65 jd_item['service_rate'] = service_rate66 67 logistics_grades = ''68 logistics_rate = ''69 if soup.find_all("div", class_='j-score')[1].find_all("div", class_='item-180 f14')[2].find("span", class_='f24 ce5393d score-180'): #高于同行业70 logistics_grades = soup.find_all("div", class_='j-score')[1].find_all("div", class_='item-180 f14')[2].find("span", class_='f24 ce5393d score-180').string71 logistics_rate = soup.find_all("div", class_='j-score')[1].find_all("span", class_='percent')[2].string72 elif soup.find_all("div", class_='j-score')[1].find_all("div", class_='item-180 f14')[2].find("span", class_='f24 c82c161 score-180'): #低于同行业73 logistics_grades = soup.find_all("div", class_='j-score')[1].find_all("div", class_='item-180 f14')[2].find("span", class_='f24 c82c161 score-180').string74 logistics_rate = '-' + soup.find_all("div", class_='j-score')[1].find_all("span", class_='percent')[2].string75 jd_item['logistics_grades'] = logistics_grades76 jd_item['logistics_rate'] = logistics_rate77 78 describ_grades = ''79 describ_rate = ''80 if soup.find_all("div", class_='j-score')[1].find_all("div", class_='item-180 f14')[3].find("span", class_='f24 ce5393d score-180'): #高于同行业81 describ_grades = soup.find_all("div", class_='j-score')[1].find_all("div", class_='item-180 f14')[3].find("span", class_='f24 ce5393d score-180').string82 describ_rate = soup.find_all("div", class_='j-score')[1].find_all("span", class_='percent')[3].string83 elif soup.find_all("div", class_='j-score')[1].find_all("div", class_='item-180 f14')[3].find("span", class_='f24 c82c161 score-180'): #低于同行业84 describ_grades = soup.find_all("div", class_='j-score')[1].find_all("div", class_='item-180 f14')[3].find("span", class_='f24 c82c161 score-180').string85 describ_rate = '-' + soup.find_all("div", class_='j-score')[1].find_all("span", class_='percent')[3].string86 jd_item['describ_grades'] = describ_grades87 jd_item['describ_rate'] = describ_rate88 89 return_grades = ''90 return_rate = ''91 if soup.find_all("div", class_='j-score')[1].find_all("div", class_='item-180 f14')[4].find("span", class_='f24 ce5393d score-180'): #高于同行业92 return_grades = soup.find_all("div", class_='j-score')[1].find_all("div", class_='item-180 f14')[4].find("span", class_='f24 ce5393d score-180').string93 return_rate = soup.find_all("div", class_='j-score')[1].find_all("span", class_='percent')[4].string94 elif soup.find_all("div", class_='j-score')[1].find_all("div", class_='item-180 f14')[4].find("span", class_='f24 c82c161 score-180'): #低于同行业95 return_grades = soup.find_all("div", class_='j-score')[1].find_all("div", class_='item-180 f14')[4].find("span", class_='f24 c82c161 score-180').string96 return_rate = '-' + soup.find_all("div", class_='j-score')[1].find_all("span", class_='percent')[4].string97 jd_item['return_grades'] = return_grades98 jd_item['return_rate'] = return_rate99 100 process_data = soup.find_all("div", class_='j-score')[2].find_all("div", class_='item-90')[0].find_all('span', class_='f16 value')[0].string101 process_data_average = soup.find_all("div", class_='j-score')[2].find_all("div", class_='item-90')[0].find_all('span', class_='f16 value')[1].string102 103 trade_data = soup.find_all("div", class_='j-score')[2].find_all("div", class_='item-90')[1].find_all('span', class_='f16 value')[0].string104 trade_data_average = soup.find_all("div", class_='j-score')[2].find_all("div", class_='item-90')[1].find_all('span', class_='f16 value')[1].string105 106 #return_data = soup.find_all("div", class_='j-score')[2].find_all("div", class_='item-90')[2].find_all('span', class_='f16 value')[0].string107 #return_data_average = soup.find_all("div", class_='j-score')[2].find_all("div", class_='item-90')[2].find_all('span', class_='f16 value')[1].string108 109 jd_item['process_data'] = process_data110 jd_item['process_data_average'] = process_data_average111 jd_item['trade_data'] = trade_data112 jd_item['trade_data_average'] = trade_data_average113 jd_item['return_data'] = ''114 jd_item['return_data_average'] = ''115 116 break_law_times = int(soup.find_all('div', class_='j-score hegui-info')[0].find_all('a')[0].string)117 jd_item['break_law_times'] = break_law_times118 jd_item['detail_url'] = response.url119 #jd_item['shop_url'] = self.shop_domain_map[response.url] 120 print jd_item121 else:122 is_success = 0123 jd_item['detail_url'] = ''124 jd_item['shop_url'] = '' 125 jd_item['is_success'] = is_success126 jd_item['response_url'] = response.url127 jd_item['create_time'] = date.get_now_time()128 yield jd_item129 130 ...

Full Screen

Full Screen

Vuln_detailes.py

Source:Vuln_detailes.py Github

copy

Full Screen

...10 nvd = requests.get(link1)11 soup1 = BeautifulSoup(nvd.content,'html.parser')12 descrip = description13 print("Impact: \n")14 #for i in range(len(soup1.find_all('div',class_="col-md-6",id="p_lt_WebPartZone1_zoneCenter_pageplaceholder_p_lt_WebPartZone1_zoneCenter_VulnerabilityDetail_VulnFormView_Vuln2CvssPanel")[0].find_all('h5'))):15 ##cvssVer = soup1.find_all('div',class_="col-md-6",id="p_lt_WebPartZone1_zoneCenter_pageplaceholder_p_lt_WebPartZone1_zoneCenter_VulnerabilityDetail_VulnFormView_Vuln2CvssPanel")[0].find_all('h5')[0].get_text(strip=True)16 ##cvssVer1 = soup1.find_all('div',class_="col-md-6",id="p_lt_WebPartZone1_zoneCenter_pageplaceholder_p_lt_WebPartZone1_zoneCenter_VulnerabilityDetail_VulnFormView_Vuln2CvssPanel")[0].find_all('h5')[1].get_text(strip=True)17 #cvssBaseHead = soup1.find_all('div',class_="col-md-6",id="p_lt_WebPartZone1_zoneCenter_pageplaceholder_p_lt_WebPartZone1_zoneCenter_VulnerabilityDetail_VulnFormView_Vuln2CvssPanel")[0].find_all('dt')[0].get_text(strip=True)18 #cvssBaseScore = soup1.find_all('div',class_="col-md-6",id="p_lt_WebPartZone1_zoneCenter_pageplaceholder_p_lt_WebPartZone1_zoneCenter_VulnerabilityDetail_VulnFormView_Vuln2CvssPanel")[0].find_all('dd')[0].get_text(strip=True)19 #print(cvssBaseHead,cvssBaseScore)20 #print(cvssVer)21 lenSoupofCVSS = len(soup1.find_all('div',class_="col-md-6",id="p_lt_WebPartZone1_zoneCenter_pageplaceholder_p_lt_WebPartZone1_zoneCenter_VulnerabilityDetail_VulnFormView_Vuln2CvssPanel")[0].find_all('dt'))22 for upIndex in range(len(soup1.find_all('div',class_="col-md-6",id="p_lt_WebPartZone1_zoneCenter_pageplaceholder_p_lt_WebPartZone1_zoneCenter_VulnerabilityDetail_VulnFormView_Vuln2CvssPanel"))):23 for index in range(lenSoupofCVSS):24 impactHeading = soup1.find_all('div',class_="col-md-6",id="p_lt_WebPartZone1_zoneCenter_pageplaceholder_p_lt_WebPartZone1_zoneCenter_VulnerabilityDetail_VulnFormView_Vuln2CvssPanel")[upIndex].find_all('dt')[index].get_text(strip=True)25 impactHeadValue = soup1.find_all('div',class_="col-md-6",id="p_lt_WebPartZone1_zoneCenter_pageplaceholder_p_lt_WebPartZone1_zoneCenter_VulnerabilityDetail_VulnFormView_Vuln2CvssPanel")[upIndex].find_all('dd')[index].get_text(strip=True)26 try:27 vulnType = soup1.find_all('ul')[16].get_text(strip=True)28 link_det = soup1.find_all('ul')[16].find_all('a')[0].get_text(strip=True)29 print(vulnType)30 except IndexError:31 vulnType = "N/A"32 print(vulnType)33#Function calling34 advisories(cveid,vulnType,impactHeading,impactHeadValue,soup1,descrip)35 #print(impactHeading,impactHeadValue)36 #if index == 3:37 #print('\n',cvssVer1,'\n')38 #continue39 #get_det = soup1.find_all('div',class_="col-md-6",id="p_lt_WebPartZone1_zoneCenter_pageplaceholder_p_lt_WebPartZone1_zoneCenter_VulnerabilityDetail_VulnFormView_Vuln2CvssPanel")40 #get_in_text = get_det[0].get_text(strip=True)41 #print("Impact: ")42 #print(get_in_text)43 #print("\n Vuln Type: \n")44 '''try:45 vulnType = soup1.find_all('ul')[16].get_text(strip=True)46 link_det = soup1.find_all('ul')[16].find_all('a')[0].get_text(strip=True)47 print(vulnType)48 except IndexError:49 vulnType = "N/A"50 print(vulnType)51'''52def advisories(cve,vulnT,impactHeading,impactHeadValue,soup1,description):53 print("\n Advisories: \n")54 try:55 for i in range(2,len(soup1.find_all('tr'))):56 if len(soup1.find_all('tr')[i].find_all('td')) == 0:57 break58 adv_link = soup1.find_all('tr')[i].find_all('td')[0].get_text(strip=True)59 adv_resource = soup1.find_all('tr')[i].find_all('td')[1].get_text(strip=True)60 adv_type = soup1.find_all('tr')[i].find_all('td')[2].get_text(strip=True)61 adv_source = soup1.find_all('tr')[i].find_all('td')[3].get_text(strip=True)62 adv_name = soup1.find_all('tr')[i].find_all('td')[4].get_text(strip=True)63 print('\n',adv_link,'\n',adv_resource,'\n',adv_type,'\n',adv_source,'\n',adv_name,'\n')64 65 #advi = soup1.find_all('table',class_="table table-striped table-condensed")[0].get_text(strip=True)66 except IndexError:67 print("N/A")68def descGrab(cve):69 #link = "https://nvd.nist.gov/vuln/detail/" + str(cve)70 link = "https://cve.mitre.org/cgi-bin/cvename.cgi?name=%20" + str(cve)71 page = requests.get(link)72 soup = BeautifulSoup(page.content, 'html.parser')73 #description = soup.find_all('p')[1].get_text()74 description = soup.find_all('td')[8].get_text()75 impactDet(cve,description)76 print("Description: ")77 print(description)78def main():79 global cvssVer80 global cvssVer181 global impactHeading82 global impactHeadValue83 global vulnType84 global adv_link85 global adv_resource86 global adv_type87 global adv_source88 global adv_name89 global Ip_Adress90 Ip_Adress = "babablacksheep.xyz"91 global Dir_Name92 Dir_Name = "/abc/"93 descGrab(sys.argv[1])94 95if __name__ == '__main__':96 main()97#soup.find_all('p')[1].get_text() #for description98#soup.find_all(class_="col-lg-8 col-md-6 col-sm-12")...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Selene automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful