Skip to content

Commit 65287ef

Browse files
17
1 parent 8d573f3 commit 65287ef

File tree

2 files changed

+34
-7
lines changed

2 files changed

+34
-7
lines changed

17.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
1-
import http.cookiejar, urllib.request, urllib.parse
1+
from http.cookiejar import CookieJar
2+
import urllib.parse
23
import bz2
3-
import http.cookies
4+
import requests
45

56

67
def main():
7-
cookie_jar = http.cookiejar.CookieJar()
8+
first_step()
9+
# second_step()
10+
11+
12+
def first_step():
13+
cookie_jar = CookieJar()
814
opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cookie_jar))
915
ary = []
1016
next_number = open_url(cookie_jar, opener, "12345", ary)
@@ -17,8 +23,7 @@ def main():
1723
print("ary length is {}".format(len(ary)))
1824
print("bs is {}", encoded_string)
1925
password = bz2.decompress(str.encode(encoded_string, "latin1"))
20-
print("pw is {}".format(password))
21-
26+
print("{}".format(password.decode()))
2227

2328

2429
def open_url(cookie_jar, opener, number, ary):
@@ -52,5 +57,13 @@ def find_next_number(doc):
5257
return number
5358

5459

60+
def second_step():
61+
php_url = "http://www.pythonchallenge.com/pc/stuff/violin.php"
62+
cookies = {"info":"the flowers are on their way"}
63+
res = requests.get(php_url, cookies=cookies)
64+
response_doc = res.text
65+
print(response_doc)
66+
67+
5568
if __name__ == "__main__":
5669
main()

README.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,22 @@ gunzip deltas.gz
1010

1111
#### 17
1212
result: http://www.pythonchallenge.com/pc/return/balloons.html
13-
14-
1.
13+
```python
14+
from http.cookiejar import CookieJar
15+
import urllib.parse
16+
import bz2
17+
import requests
18+
```
19+
- the small pic in left bottom director us to [Level 3](http://www.pythonchallenge.com/pc/def/linkedlist.php)
20+
- use CookieJar to catch cookies
21+
- use bz2 to decompress
22+
23+
> is it the 26th already? call his father and inform him that "the flowers are on their way". he\'ll understand.
24+
- 26th director us to [Level 15](http://www.pythonchallenge.com/pc/return/uzi.html)
25+
- mozart‘s farther is *Leopold Mozart*
26+
- *call* director us to [phonebook in Level 12](http://www.pythonchallenge.com/pc/phonebook.php)
27+
- Level 12 *Bert* tell us to use the first name
28+
- inform him let us remember that the cookies are {"info":"value"}
1529

1630
#### 16
1731
result: http://www.pythonchallenge.com/pc/return/romance.html

0 commit comments

Comments
 (0)