I am very new to python programming. Emphasis on VERY. I am trying to set up my first web scraping project (for news article curation).
I have already managed to scrape the news site and to create a loop that organizes the results how I want them. My issue is that I plan on scraping the web page once a day, but only for the publications that were published that same day. I don't want all of them because that would mean I would get a lot of repetition.
I know that it has something to do with converting the date via the datetime module (with an if statement), but for the life of me I couldn't find a way to make it work.
In the html, this is an example of how the date is displayed:
<time datetime="2019-02-24T10:30:46+00:00">Feb 24, 2019 at 10:30</time>
This is what I have so far:
from urllib.request import urlopen as uReq
from bs4 import BeautifulSoup as soup
from datetime import datetime
my_url = "https://www.coindesk.com/category/business-news/legal"
# Opening up the website, grabbing the page
uFeedOne = uReq(my_url, timeout=5)
page_one = uFeedOne.read()
uFeedOne.close()
# html parser
page_soup1 = soup(page_one, "html.parser")
# grabs each publication block
containers = page_soup1.findAll("a", {"class": "stream-article"} )
for container in containers:
link = container.attrs['href']
publication_date = "published on " + container.time.text
title = container.h3.text
description = "(CoinDesk)-- " + container.p.text
print("link: " + link)
print("publication_date: " + publication_date)
print("title: " + title)
print("description: " + description)