Best Python code snippet using selene_python
create_cities.py
Source:create_cities.py
...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__':...
jd_spider.py
Source:jd_spider.py
...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
...
Vuln_detailes.py
Source:Vuln_detailes.py
...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")...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!