I have a problem with parsing links with Python. There is my code:
def get_content(html):
soup = BeautifulSoup(html, 'lxml')
items = soup.find_all('div', class_='grid-item___eaXVb')
for item in items:
link = item.find('a', class_='gl-product-card__details-link')
print(link.get('href'))
And I get this error:
Traceback (most recent call last):
File "parser.py", line 32, in <module>
parse()
File "parser.py", line 27, in parse
get_content(html.text)
File "parser.py", line 21, in get_content
print(link.get('href'))
AttributeError: 'NoneType' object has no attribute 'get'
But when I try this:
for item in items:
link = item.find('a', class_='gl-product-card__details-link')
print(type(link))
I get a repsonse, that all link have type:
<class 'bs4.element.Tag'>
<class 'bs4.element.Tag'>
...
...
...
<class 'bs4.element.Tag'>
<class 'bs4.element.Tag'>
Where did I make a mistake? What's wrong?
urlin you post.