Answer the question
In order to leave comments, you need to log in
How to parse elements using BeautifulSoup?
Hello. Here is the part of my parser that gets the prices:
def get_soup(lp: list):
for i in lp:
with open('html.txt', 'w', encoding='utf-8') as f:
response = requests.get(i, headers=headers, cookies=cookies)
f.write(response.text)
with open("html.txt", encoding='utf-8') as nf:
soup = BeautifulSoup(nf, 'html.parser')
tags = soup.find(lambda tag: tag.name == 'div' and tag.get('class') == ['n_6'])
for prices in tags.find_all('span', class_='N_1'):
price_re = re.sub(r'\D', '', *prices)
price.append(price_re)
for p_prices in tags.find_all('p', class_='N_'):
p_price_re = re.sub(r'\D', '', *p_prices)
p_price.append(p_price_re)
<div class="NZ N_2"><p class="N_">3 149 ₽</p><p class="N_0"><span class="N_1">4 999 ₽</span></p></div>
in
and is
it doesn't work because the whole page is parsed. Is parsing each product separately the only way out? I would like to implement this with BeautifulSoup
Answer the question
In order to leave comments, you need to log in
I suppose, instead of writing prices in a list, it is better to organize a dictionary in which you write normal prices under numbered keys, and write a promo price in the “promo” key.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question