Answer the question
In order to leave comments, you need to log in
How can I make .find() look for and retrieve data from the last element on the page?
For example, there are two elements on the page:
And with the help of .find() I need to find and pick up the div on the line with the number two (i.e. I need to find the very last div on the page). Preferably using the class in the tag, if it exists.
Answer the question
In order to leave comments, you need to log in
from bs4 import BeautifulSoup as bs
import requests as req
url = "https://url.ru"
headers = {
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.51 Safari/537.36'
}
headers = {'Accept'}
html = bs(req.get(url, headers=headers).text, 'lxml')
div = html.find_all('div', _class='class')[-1]
print(div)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question