Try this:
from pprint import pprint
import bs4
import requests
resp = requests.get("https://www.visitmonmouth.com/page.aspx?Id=5017")
assert resp.status_code == 200
soup = bs4.BeautifulSoup(resp.content, 'html.parser')
dates = []
links = []
for tag in soup.find('div', {'id': 'content'}).find_all('li'):
date = str(tag.contents[0]).strip().replace(':', '').split(' ')[0]
if date.count('/') == 2: # should use regexp here.
a = tag.find('a')
if a is not None:
href = a.attrs['href'].strip()
if href.startswith('http'): # same should use regexp here.
print(date, href)
dates.append(date)
links.append(href)
my_dict = dict(zip(dates, links))
pprint(my_dict, indent=2)
The output will look like:
7/18/20 https://www.co.monmouth.nj.us/PressDetail.aspx?ID=2962
7/17/20 https://www.co.monmouth.nj.us/PressDetail.aspx?ID=2960
7/16/20 https://www.co.monmouth.nj.us/PressDetail.aspx?ID=2959
7/15/20 https://www.co.monmouth.nj.us/PressDetail.aspx?ID=2958
7/14/20 https://www.co.monmouth.nj.us/PressDetail.aspx?ID=2956
7/13/20 https://www.co.monmouth.nj.us/PressDetail.aspx?ID=2955
7/12/20 https://www.co.monmouth.nj.us/PressDetail.aspx?ID=2954
And the data will be be available in a dictionary called my_dict
.