Hi, I am trying to get "href" of a beautiful soup tag but I am getting None value everytime

Viewed 21
    page_grab = soup.find_all("ul",{"class":"news_list large"})
    for i in page_grab:
       print(i.href)

this is my code and it turns 'None' value

1 Answers

It would probably be useful if we could see the ul tags in the HTML / any of the HTML.

Regardless, beautifulSoup returns a set of elements, so the for loop is correct. However, beautifulSoup uses a get method on the element classes to obtain attributes, so you would use i.get('href') to get the href attribute value.

Perhaps this would be useful to look at: Extracting attribute with beautifulSoup

Related