Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

beautifulsoup with same name tag, but different use

samediv

So i have this code

for j in links:
    Title = j.find('p').text.strip()
    Narration = j.find('p').text.strip()

    Link = j.find('a')['href'].strip()
    Date = j.find('time').text[-14:-1].strip()
    Label = '1'

But i have a trouble with it because theres 2 same <p> tag within the same div,but it has different use

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Title = News Title
Narration = News Narration

is there any way to differentiate the <p> tags?

>Solution :

It needs some HTML code to clarify, but as I understand correct you have to use find_next('p') on the first find('p'):

for j in links:
    Title = j.find('p').text.strip()
    Narration = j.find('p').find_next('p').text.strip()
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading