I have a folder of similar-looking scripts which scrape google alerts from their RSS feeds.
All the files are exactly the same except the variable uniqueurl
at the end of url
url = 'https://www.google.co.in/alerts/feeds/*uniqueurl*'
resp = requests.get(url)
soup = BeautifulSoup(resp.text, 'html.parser')
output = []
for entry in soup.find_all('entry'):
item = {
'Title': entry.find('title', {'type': 'html'}).text,
'Pubdate': entry.find('published').text,
'Content': entry.find('content').text,
'Link': entry.find('link')['href']
}
output.append(item)
df = pd.DataFrame(output)
df.to_csv('google_alert.csv',index=False)
How do I run a command like python create.py uniqueurl
which generates the above file with just the url variable updated with what is passed in the command?