How to get two tags in findall using BeautifulSoup

0 votes

I want to extract data from 2 tags that are related. I have written code to extract the 1st tag.

html = driver.page_source
soup = BeautifulSoup(html)
for tag in soup.find_all(['a']):
    print (tag.text)

I want to extract the 2nd tag in the same loop. How can I do this?

Apr 2, 2019 in Python by Rishab
21,033 views

1 answer to this question.

0 votes

You can mention both the tags in the same find_all. Like this

html = driver.page_source
soup = BeautifulSoup(html)
i = 0
for tag in soup.find_all(['a',’div’]):
    print (tag.text)
answered Apr 2, 2019 by Giri

Related Questions In Python

0 votes
1 answer
0 votes
1 answer

How to get textual output when using exceptions in Python?

Hi, the answer is pretty simple.  Without the ...READ MORE

answered Jan 17, 2019 in Python by Nymeria
• 3,560 points
976 views
0 votes
1 answer

How to get value in Pandas dataframe using index?

You can use the iloc method to do ...READ MORE

answered Apr 8, 2019 in Python by Rohit
8,299 views
0 votes
1 answer
0 votes
1 answer

How to web scrape using python without using a browser?

Yes, you can use the headless mode. ...READ MORE

answered Apr 2, 2019 in Python by Yogi

edited Oct 7, 2021 by Sarfaraz 13,066 views
0 votes
1 answer

How to parse html file to BeautifulSoup?

Hey. Refer to the following code: driver.get("link") html = ...READ MORE

answered Apr 2, 2019 in Python by Kirti
1,936 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP