-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlevel04.py
More file actions
35 lines (27 loc) · 1.05 KB
/
Copy pathlevel04.py
File metadata and controls
35 lines (27 loc) · 1.05 KB
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
31
32
33
34
35
# http://www.pythonchallenge.com/pc/def/linkedlist.html
# http://www.pythonchallenge.com/pc/def/linkedlist.php
# http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=12345
import re
import requests
# pattern = r'\d+'
pattern = r'next nothing is (\d+)'
template = u'http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing={}'
def request_from(num):
url = template.format(num)
resp = requests.get(url)
text = resp.text
print(text)
match = re.search(pattern, text)
if match:
num = match.group(1)
request_from(num)
if __name__ == '__main__':
# request_from('12345')
# http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=16044
# Yes. Divide by two and keep going.
# request_from('8022')
# http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=82682
# There maybe misleading numbers in the text.
# One example is 82683. Look only for the next nothing and the next nothing is 63579
request_from('63579')
# http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=66831