return outside selection что делать?
Код не запускается из-за return, подскажите почему так и как это исправить, буду очень благодарен
def get_all_pages():
headers = {
'user-agent' :'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.71 Safari/537.36'
}
r = requests.get(url='https://winauto.ua/index.php?match=all&subcats=y&pcode_from_q=y&pshort=y&pfull=y&pname=y&pkeywords=y&search_performed=y&q=gazer&dispatch=products.search&items_per_page=128&search_id=37901&page=1')
if not os.path.exists("data"):
os.mkdir("data")
with open("data/page_1.html", "w") as file:
file.write(r.text)
with open("data/page_1.html") as file:
src = file.read()
soup = BeautifulSoup(src, "lxml")
pages_count = int(soup.find("div", class_="ty-pagination__items").find_all(class_="cm-history ty-pagination__item cm-ajax")[-1].text)
for i in range(1,pages_count + 1):
url = f'https://winauto.ua/index.php?match=all&subcats=y&pcode_from_q=y&pshort=y&pfull=y&pname=y&pkeywords=y&search_performed=y&q=gazer&dispatch=products.search&items_per_page=128&search_id=37901&page={i}'
r = requests.get(url=url,headers=headers)
with open(f'data/page_{i}.html','w') as file:
file.write(r.text)
time.sleep(4)
return pages_count + 1