I have an crawler in python for get brands of vehicles.
My function return an array with all brands and search for models each brand.
But some brands do not have models and I would like that when the brands did not have models it would skip to the next brand and not finish running the script.
I try this:
all_brands = [u'Acura', u'Alfa Romeo', u'Asia', u'Aston Martin', u'Audi', u'Bentley', u'BMW', u'Buggy BRM', u'Buick', u'Cadillac', u'Carver Concept', u'Chamonix', u'Changan (Chana)', u'Chery', u'Chevrolet', u'Chrysler', u'Citroen', u'CN Auto', u'Crosslander', u'Daewoo', u'Daihatsu', u'Dodge', u'DS', u'Effa', u'Engesa', u'Envemo', u'Fargo', u'Ferrari', u'Fiat', u'Ford', u'Fyber Buggy', u'Geely', u'GMC', u'Great Wall', u'Gurgel', u'Hafei Towner', u'Haima', u'Honda', u'Hummer', u'Hyundai', u'Infiniti', u'Isuzu', u'Iveco', u'JAC', u'Jaguar', u'Jeep', u'JIN BEI', u'Jonway', u'JPX', u'Kia', u'Lada', u'Lamborghini', u'Land Rover', u'Landwind', u'Lexus', u'Lifan', u'Lincoln', u'Lobini', u'Lotus', u'Mahindra', u'Maserati', u'Matra', u'Mazda', u'McLaren', u'Mercedes Benz', u'MG', u'MG Spayc', u'MINI', u'Mitsubishi', u'Nissan', u'Oldsmobile', u'Pagani', u'Peugeot', u'Plymouth', u'Pontiac', u'Porsche', u'Rely', u'Renault', u'Rolls-Royce', u'Saab', u'Saturn', u'Seat', u'Shineray', u'Shuanghuan', u'Smart', u'Spyker', u'SsangYong', u'Subaru', u'Sunbeam', u'Suzuki', u'TAC', u'Tesla', u'Toyota', u'Troller', u'Volkswagen', u'Volvo']
for brand in all_brands:
soup_brand = get_html(link_base + str(brand_url))
if soup_brand is None:
return
print "Crawleando: "+str(count_url)+"/"+str(count_brands)
print "Marca atual: "+brand_url
first_vehicle = soup_brand.find(attrs={"class":"titulo_anuncio"})
if first_vehicle is None:
return #Here it was to jump to next tag but it to the script