Issue
I am veeeeeryyyyy nooob...
I'm trying to scrape this page https://dungeonsanddragons.fandom.com/it/wiki/Allarme
and i would like to extract the text after the string Gittata: (in this case, i'd like to have 9 metri) Any hint? thanks a lot LV
Unfortunately I don't recognize any tag I can use, I'd like to "print text from the N line"
This is my code
import requests
from bs4 import BeautifulSoup
url = "https://dungeonsanddragons.fandom.com/it/wiki/Aiuto"
data = requests.get(url).text
soup = BeautifulSoup(data, 'html.parser')
#GITTATA
gittata = soup.find_all('p')[1]
...that's all
Solution
Try to find <b>
tag with text Gittata
and then get next sibling string:
import requests
from bs4 import BeautifulSoup
url = "https://dungeonsanddragons.fandom.com/it/wiki/Aiuto"
data = requests.get(url).text
soup = BeautifulSoup(data, "html.parser")
g = soup.select_one("b:-soup-contains(Gittata)").find_next_sibling(string=True).strip()
print(g)
Prints:
9 metri
Answered By - Andrej Kesely
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.