jeudi 9 septembre 2021

Exctract only certain links from website with if statement Python and BeautifulSoup

This is a excerpt from a crawled website (I included a Image in this post), I think this is enough to understand what I want to do.

For example in there is no i dont want to collect those links ().

But in there is a here I want to collect all the links () that are available.

What I already tried myself:

for link4 in doc.find_all("li",{"data-id":"10"}):

link_test = link4.find_all("li",{"data-id":True})
print(link4.prettify())

print(link4.prettify())

link_neu2 = link4.find_all("li",{"class":""},"data-id") if i

print(link_neu2)

link_neu = link4.find_all(attrs={"class":"flag"})

print(link_neu)

print(link4.prettify())

if "flag" in link_neu:

    print(link_neu)

for flag in link4("i",{"class":"flag"}):

    print(flag.prettify())
    

for parent_flag in flag.parent: print(parent_flag.name)

for l1 in link_neu:

if link_neu.find_all("i",{"class":"flag"}) in l1:

print(link_neu)

linkb = l1.find_all("a")

print(linkb)

if "flag" in str(link_n)

Aucun commentaire:

Enregistrer un commentaire