Created
November 3, 2023 13:41
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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