-
Notifications
You must be signed in to change notification settings - Fork 0
/
__init__.py
30 lines (21 loc) · 854 Bytes
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from requests import get
from bs4 import BeautifulSoup
from IPython.core.display import display, HTML
def leet_puzzle(problem):
html = '<a href="https://leetcode.com/problems/' + problem
html += '">Source : https://leetcode.com/problems/' + problem + '</a>'
response = get('https://leetcode.com/problems/' + problem)
soup = BeautifulSoup(response.content)
content = soup.select('.question-content')[0]
for a in content.select('a'):
if a['href'] == '/subscribe/':
a.nextSibling.extract()
a.extract()
else:
a['href'] = 'https://leetcode.com' + a['href']
for tags in content.select('#tags'):
tags.extract()
for similar in content.select('#similar'):
similar.extract()
html += str(content)
display(HTML(html))