Solution 1 :

You can do like this:

from bs4 import BeautifulSoup
import requests

url = ''
r = requests.get(url)
soup = BeautifulSoup(r.text,'lxml')
a = soup.find('div', class_='speaker_social_wrap').find_all('a')
for i in a:

Solution 2 :

Your selector gives you the div not the urls array. You need something more like:

social_media_div = soup.find_all('div', class_ = 'foo')
social_media_anchors = social_media_div.find_all('a')
for anchor in social_media_anchors:

Problem :

I have a div tag which contains three anchor tags and have url in them.
I am able to print those 3 hrefs but they get merged into one value.
Is there a way I can get three seperate values.

Div looks like this:

<div class="speaker_social_wrap">
<a href="" target="_blank">
    <i aria-hidden="true" class="x-icon x-icon-twitter" data-x-icon-b=""></i>
<a href="" target="_blank">
    <i aria-hidden="true" class="x-icon x-icon-linkedin-in" data-x-icon-b=""></i>
<a href="" target="_blank">
<i aria-hidden="true" class="x-icon x-icon-facebook-f" data-x-icon-b=""></i>

What I have tried so far:

social_media_url = soup.find_all('div', class_ = 'foo')
  for url in social_media_url:

Expected Result:


My Output

<div><a twitter-url><a linkedin-url><a facebook-url></div>


Comment posted by Raspberry Lemon

Corrected my html..can you check once again

Comment posted by Ram

Updated the answer. Please check.

Comment posted by Raspberry Lemon

AttributeError: ‘NoneType’ object has no attribute ‘find_all’ Getting this error

Comment posted by Ram

If your HTML code is different, then you will obviously get that error. Did you copy my answer and ran it ? Did you get any such error then ?

Comment posted by Ram

It would be better if you post the exact HTML code you have or the URL @RaspberryLemon