C
C
Collonil Tolli2021-05-23 22:02:06
Python
Collonil Tolli, 2021-05-23 22:02:06

How to fix AttributeError: 'NoneType' object has no attribute 'find_all'?

Googled for a long time, but I still can't figure out what's wrong?
Gives: AttributeError: 'NoneType' object has no attribute 'find_all'

As I understand it, it does not find the required block, but how can I fix it?
I'm trying to parse a username from a page in VK

import requests;from bs4 import BeautifulSoup

link = input("")
responce = requests.get(link).text
soup = BeautifulSoup(responce, 'lxml')
block = soup.find('div', id = "page_info_wrap")
check_nikname = block.find_all('h1')[0].text
print(check_nikname)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
Yupiter7575, 2021-05-23
@yupiter7575

import requests;from bs4 import BeautifulSoup
In my homeland, for this they are shot on the spot

responce = requests.get(link).text
soup = BeautifulSoup(responce, 'lxml')

response in translation means "answer". And you have html markup in your answer, the variable name is not correctly chosen. Yes, and it is written respon s e
block = soup.find('div', id = "page_info_wrap")
Throw off the link where you saw it written that way. Of course, he does not find it. The correct syntax as stated in the documentation is:
block = soup.find('div', attrs={"id":"page_info_wrap"}

And if possible, it is better to search only by tag or by class.
check_nikname = block.find_all('h1')[0].text
And finally, the variable name is not correctly chosen. check is a verb, verbs are used in the names of Functions
UPD:
I re-read the question. And why are you parsing VK through requests? They have their own api

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question