Robin schrieb:
> also ich habe da jetzt 2 Tage lang herumprobiert, aber ich bekomme es
> nicht hin.
>
>
1 | > My_URL = BeautifulSoup(urlopen("pfad"), "html.parser")
|
2 | >
|
3 | > result = My_URL.findAll("span", {"itemprop": "name"})
|
4 | > print (result)
|
5 | >
|
>
>
1 | > Aber wie bekomme ich das html in Text?
|
2 | > print (result.text)
|
3 | >
|
4 | > AttributeError: 'ResultSet' object has no attribute 'text'
|
5 | >
|
"result" ist eine Instanz der Klasse "ResultSet", das ist im Prinzip
eine Liste von Instanzen der Klasse "bs4.element.Tag". Was Du jedoch
willst, ist
1 | results = My_URL.findAll('span')[0:2] # man beachte das slice am Ende
|
2 | for result in results:
|
3 | print result.getText()
|
oder für Fortgeschrittene mit List Comprehension:
1 | print [a for a in My_URL.findAll('span')[0:2]]
|