I am trying to scrap data from this site.
I want to create a csv/excel file scraping data from link.
At first, we need to extract the blog articles title, date amd link from the page ( in this page 11 article), then store in a file. Like this,
My attempt:
Here, Firstly, I tried to extract the blog links but there were also some unwanted link
import httplib2
import csv
from bs4 import BeautifulSoup, SoupStrainer
http = httplib2.Http()
links = []
status, response = http.request(f'https://www.forexcrunch.com/category/forex-weekly-outlook/gbp-usd-outlook/page/24/')
for link in BeautifulSoup(response,'html.parser', parse_only=SoupStrainer('a')):
if link.has_attr('href'):
if 'gbp' in link['href'] :
if link['href'] not in links:
print(link['href'])
links.append(link['href'])
From these links the blog article containing weekly forecast need to be filtered. Then, from link article date and title should retrieve and store them,
header = ['Year', 'Date', 'Title', 'Link']
f = open('summary.csv', 'w')
writer = csv.writer(f)
writer.writerow(header)
for link in links :
data = [Year,Date,Title,Article Link] # get link data and store
writer.writerow(data)
f.close()
