def find_course(page): finder = Finder() finder.set_data(page) name_pattern = '"(.+)"' names = finder.find_references(name_pattern) price_pattern = '(\d+) дн / (\d+) р.' prices = finder.find_references(price_pattern) i0 = 0 for name in names: print(name) c = Course(site_id=s.id, name=name) c.save() of1 = Offer(course_id=c.id, duration_hours=0, duration_days=prices[i0][0], price=prices[i0][1]) of2 = Offer(course_id=c.id, duration_hours=0, duration_days=prices[i0 + 1][0], price=prices[i0 + 1][1]) i0 += 2 of1.save() of2.save() return []
'days': item[1], 'hours': item[0], 'full_price': price[i0], 'special_price': price[i0 + 1] }) i0 += 2 return result res = bp.start_parse(find_links, options=(1, 4)) s = Site(name='pedobychenie.rf') s.save() progress = 0 max_ = len(res) for link, name in res: progress += 1 print(f'{round(progress / max_ * 100, 2)}%') bp.set_url(f'https://xn--90afccar8afg8b5b.xn--p1ai{link}') prices = bp.start_parse(find_price, False) c = Course(site_id=s.id, name=name) c.save() for price in prices: Offer(course_id=c.id, duration_hours=price['hours'], duration_days=price['days'], price=price['full_price']).save()