Skip to content

Instantly share code, notes, and snippets.

@clbarnes
Created November 3, 2023 13:41
Show Gist options
  • Save clbarnes/f30085fa6e47be15147459194dde5b45 to your computer and use it in GitHub Desktop.
Save clbarnes/f30085fa6e47be15147459194dde5b45 to your computer and use it in GitHub Desktop.
Scrape Project Euler and create stub python scripts for each (ancient code, transferred from old account)
#!/usr/bin/python
from bs4 import BeautifulSoup
import urllib
path = '/home/tunisia/Desktop/Project Euler/'
for probnum in range(1,444):
html = BeautifulSoup(urllib.urlopen('http://projecteuler.net/problem=%d' % probnum))
title = html.h2
title = title.get_text().replace('/','_')
filename = 'prob%d - %s.py' % (probnum, title)
pathNname = path + filename
task = html.find('div', attrs = {'class' : 'problem_content'})
task = task.get_text().strip().split('\n')
task = '\n'.join(['#' + line for line in task])
file = open(pathNname,'w')
file.write('#!/usr/bin/python\n\n' + task)
file.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment