arbeiten Ich habe einige seltsame Verhalten von findAll
‚s Methode bemerkt:BeautifulSoup wie funktioniert findAll
>>> htmls="<html><body><p class=\"pagination-container\">slytherin</p><p class=\"pagination-container and something\">gryffindor</p></body></html>"
>>> soup=BeautifulSoup(htmls, "html.parser")
>>> for i in soup.findAll("p",{"class":"pagination-container"}):
print(i.text)
slytherin
gryffindor
>>> for i in soup.findAll("p", {"class":"pag"}):
print(i.text)
>>> for i in soup.findAll("p",{"class":"pagination-container"}):
print(i.text)
slytherin
gryffindor
>>> for i in soup.findAll("p",{"class":"pagination"}):
print(i.text)
>>> len(soup.findAll("p",{"class":"pagination-container"}))
2
>>> len(soup.findAll("p",{"class":"pagination-containe"}))
0
>>> len(soup.findAll("p",{"class":"pagination-contai"}))
0
>>> len(soup.findAll("p",{"class":"pagination-container and something"}))
1
>>> len(soup.findAll("p",{"class":"pagination-conta"}))
0
Wenn wir also für pagination-container
Suche gibt es sowohl das erste und das zweite p
-Tag. Es ließ mich denken, dass es nach einer partiellen Gleichheit sucht: so etwas wie if passed_string in class_attribute_value:
. Also habe ich die Saite in findAll
Methode gekürzt und es hat nie etwas gefunden!
Wie ist das möglich?