2017-10-14 7 views

Répondre

0

Essayez ceci.

from bs4 import BeautifulSoup 

html=''' 
<li class="title"><h4><a href="/addons/wow/world-quest-tracker">World Quest Tracker</a></h4></li> 
''' 
soup = BeautifulSoup(html, "lxml") 
for item in soup.select(".title"): 
    print(item.text) 

Résultat:

World Quest Tracker 
0
html_doc = '<li class="title"><h4><a href="/addons/wow/world-quest-tracker">World Quest Tracker</a></h4></li>' 
soup = BeautifulSoup(html_doc, 'html.parser') 
print soup.find('a').text 

ce imprimera

u'World Quête Tracker »

0

Je tente d'extraire le texte inbetween les balises href

Si vous voulez réellement le texte dans l'attribut href, et non la contenu texte enveloppé par l'ancre <a></a> (votre libellé est un peu flou), utilisez get('href'):

from bs4 import BeautifulSoup 

html = '<li class="title"><h4><a href="/addons/wow/world-quest-tracker">World Quest Tracker</a></h4></li>' 
soup = BeautifulSoup(html, 'lxml') 
soup.find('a').get('href') 

'/addons/wow/world-quest-tracker'