Всем привет пишу парсер для wildberries
Вот весь код :
from bs4 import BeautifulSoup
import requests
from requests.api import head
import io
import random
import numpy
def get_html():
'''Получение html кода'''
headers = {
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36",
"accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"
}
url = 'https://www.wildberries.ru/catalog/muzhchinam/odezhda/vodolazki'
html = requests.get(url,headers=headers)
global src
src = html.text
def get_pages():
"""получение количества страниц"""
soup = BeautifulSoup(src , 'lxml')
try:
good_count = soup.find('h1').find_next('span').get_text(strip=True).replace("\xa0", '').split()[0]
pages = int(good_count) // 100 + 1
except:
pages = 1
print(f'''Количество страниц:{pages}''')
def get_price():
'''получение цены товара'''
soup = BeautifulSoup(src , 'lxml')
h1 = soup.find_all(class_="lower-price")
print(h1)
def main ():
get_price()
get_html()
get_pages()
if __name__ == '__main__':
main()
выдает ошибку :
Traceback (most recent call last):
File "C:\Users\adaml\PycharmProjects\wildparser2\app.py", line 89, in
main()
File "C:\Users\adaml\PycharmProjects\wildparser2\app.py", line 84, in main
get_price()
File "C:\Users\adaml\PycharmProjects\wildparser2\app.py", line 35, in get_price
soup = BeautifulSoup(src , 'lxml')
NameError: name 'src' is not defined