Verwenden Sie BeautifulSoup, um den Titel eines Links zu extrahieren
Ich versuche, den Titel eines Links mit BeautifulSoup zu extrahieren. Der Code, mit dem ich arbeite, lautet wie folgt:
url = "http://www.example.com"
source_code = requests.get(url)
plain_text = source_code.text
soup = BeautifulSoup(plain_text, "lxml")
for link in soup.findAll('a', {'class': 'a-link-normal s-access-detail-page a-text-normal'}):
title = link.get('title')
print title
Nun, ein Beispiellink
as Element @ enthält Folgendes:
<a class="a-link-normal s-access-detail-page a-text-normal" href="http://www.amazon.in/Introduction-Computation-Programming-Using-Python/dp/8120348664" title="Introduction To Computation And Programming Using Python"><h2 class="a-size-medium a-color-null s-inline s-access-title a-text-normal">Introduction To Computation And Programming Using <strong>Python</strong></h2></a>
Es wird jedoch nichts angezeigt, nachdem ich den obigen Code ausgeführt habe. Wie kann ich den im @ gespeicherten Wert extrahieretitle
Attribut des Anker-Tags, das in @ gespeichert ilink
?