I'm have been spending past few days in learning of python. Today I come with a topic called web scraping. I'm trying to scrape all p tag inside a div except first 3 p tag. Since there is no class or id for the p tag I can't find way to un-scrape them
My code:
from bs4 import BeautifulSoup
data = '''<div class="one">
<p style="color:red">Dummy Text</p>
<p style="color:red">Unwanted Text</p>
<p style="color:red">No Text</p>
<p style="color:red">Lorem ipsum dolor sit amet</p>
<p style="color:red">sed do eiusmod tempor incididunt</p>
<p style="color:red">consectetur adipiscing elit</p>
<p style="color:red">ut labore et dolore magna</p>
</div>'''
text = BeautifulSoup(data, 'html.parser')
for result in text.find_all('p'):
print(result.get_text())
My output:
- Dummy Text
- Unwanted Text
- No Text
- Lorem ipsum dolor sit amet
- sed do eiusmod tempor incididunt
- consectetur adipiscing elit
- ut labore et dolore magna
What I required:
- Lorem ipsum dolor sit amet
- sed do eiusmod tempor incididunt
- consectetur adipiscing elit
- ut labore et dolore magna
Since I'm new to SOF please mention in comment if I violated any of the guidelines.