mirror of
https://github.com/projekteuler/projekteuler.git
synced 2025-12-10 08:46:41 +01:00
20 lines
654 B
Python
Executable File
20 lines
654 B
Python
Executable File
import requests, json
|
|
from bs4 import BeautifulSoup
|
|
|
|
URL = "https://projecteuler.net/problem={}"
|
|
|
|
def getBS(url):
|
|
r = requests.get(url)
|
|
data = r.text
|
|
return BeautifulSoup(data,"lxml")
|
|
|
|
problems = {}
|
|
for i in range(1, 701):
|
|
print(i)
|
|
problem = getBS(URL.format(i))
|
|
problem_tag = problem.find("div", {"class":"problem_content"})
|
|
problem_title = problem.find("h2").text
|
|
problem_html = str(problem_tag).replace("project/images/", "https://projecteuler.net/project/images/")
|
|
problems[i] = {"title":problem_title, "problem":problem_html}
|
|
|
|
open("problems.json", "w"). write(json.dumps(problems, ensure_ascii=False, indent=4)) |