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 in Python by Rishab
19 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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 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 in Python by Nymeria
• 3,500 points
10 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 in Python by Rohit
18 views
0 votes
1 answer
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 in Python by Kirti
10 views
0 votes
1 answer

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.