Answer the question
In order to leave comments, you need to log in
Why is href not parsed in the tag?
The bottom line is that there is a href in the a tag - a link, if you just display the text, then it can be seen that there is a link, when I add .get('href'), writes None, what could be the problem? Here is the code
import requests
from bs4 import BeautifulSoup
def parse():
URL = 'https://www.olx.ro/moda-frumusete/incaltaminte-barbati/?view=list'
HEADERS = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36'
}
response = requests.get(URL, headers=HEADERS)
soup = BeautifulSoup(response.content, 'html.parser')
items = soup.findAll('div', class_='offer-wrapper')
ads = []
for item in items[:5]:
ads.append({
# 'title': item.find('h3', class_='lheight22 margintop5').get_text(strip=True),
'link': item.find('a', class_='marginright5 link linkWithHash detailsLink'),
# 'price': item.find('p', class_='price').get_text(strip=True)
})
print(ads)
parse()
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question