Issue
I am trying to create a news aggregator that scrapes headlines from NY Times using BeautifulSoup4.
I want to include the first 15 elements with an h3 tag on the site. However, the 9th element with a h3 tag on NY Times is an advertisement.
How can i inlude that out?
Heres my code:
ht_r = requests.get("https://www.nytimes.com/")
ht_soup = BeautifulSoup(ht_r.content, 'html.parser')
ht_headings = ht_soup.findAll('h3')
ht_headings = ht_headings[0:15]
ht_news = []
I have tried to do
del ht_headings[9]
However, I am getting this error:
SyntaxError: cannot delete function call
Solution
you can try:
ht_headings = ht_headings[:9] + ht_headings[10:]
Answered By - Alexandru DuDu
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.