This is what the HTML looks like:
detail1 1 detail2 detail3
I need to extract detail2 and detail3.
But using this code, I can only get detail1.
info = data.find("p", class_ = "details").span.text
How do I extract the required items?
Thanks in advance!
In your case, select a more specific element, i.e. select all siblingelements of aelement with class number:
soup.select('span.number ~ span')Example
Output
You can find all
and do a normal index:Output result:
Or use CSS selector:
spans = soup.select(".details span:nth-last-of-type(-n+2)") for s in spans: print(s.text)Output result: