知道了一个小游戏 http://www.pythonchallenge.com/ 尝试一下
0.
http://www.pythonchallenge.com/pc/def/0.html
2的38次方
1.
http://www.pythonchallenge.com/pc/def/274877906944.html
>>> b = ''
>>> for i in a:
if 97<= ord(i) <= 120:
b += chr(ord(i)+2)
elif ord(i) ==121 or ord(i) == 122:
b += chr(ord(i)-24)
else: b += i
>>> b
"i hope you didnt translate it by hand. thats what computers are for. doing it in by hand is inefficient and that's why this text is so long. using string.maketrans() is recommended. now apply on the url."
推荐使用 string.maketrans()方法,方案如下:
>>> import string >>> text = """g fmnc wms bgblr rpylqjyrc gr zw fylb. rfyrq ufyr ... amknsrcpq ypc dmp. bmgle gr gl zw fylb gq glcddgagclr ylb rfyr'q ... ufw rfgq rcvr gq qm jmle. sqgle qrpgle.kyicrpylq() gq pcamkkclbcb. ... lmu ynnjw ml rfc spj.""" >>> table = string.maketrans( ... string.ascii_lowercase, ... string.ascii_lowercase[2:]+string.ascii_lowercase[:2])
Now we apply the translation table on the string:
>>> string.translate(text,table) "i hope you didnt translate it by hand. thats what computers are for. doing it in by hand is inefficient and that's why this text is so long. using string.maketrans() is recommended. now apply on the url."
Alternatively, just use the translate on the "text" variable:
>>> text.translate(table) "i hope you didnt translate it by hand. thats what computers are for. doing it in by hand is inefficient and that's why this text is so long. using string.maketrans() is recommended. now apply on the url."
2.
http://www.pythonchallenge.com/pc/def/ocr.html
python获得网页源:
import requests
import re
#下面三行是编码转换的功能
import sys
#hea是一个字典,里面保存了user-agent。
#让目标网站误以为本程序是浏览器,并非爬虫。
#从网站的Requests Header中获取。【审查元素】
hea = {'User-Agent':'Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.118 Safari/537.36'}
html = requests.get('http://www.pythonchallenge.com/pc/def/ocr.html',headers = hea)
html.encoding = 'utf-8' #这一行是将编码转为utf-8否则中文会显示乱码。
#print (html.text)
源码在 html.text 中
把获得的html.text写入文件:
s_record = open('record.txt','w')
s_record.write(html.text)
s_record.close()
s_r = open('record1.txt')
s = ''
for i in s_r:
for j in i:
if 'a'<= j <= 'z' or 'A'<= j <= 'Z':
s+=j
print(s)
s_r.close()
得到结果 “equality”
3.
http://www.pythonchallenge.com/pc/def/equality.html
一直搞不出结果,看了攻略==,只有左右有大写才算,而且只能各有三个,即:xXXXxXXXx
参考:http://blog.csdn.net/Jurbo/article/details/52136323
text = open('text.txt')
a = text.readlines()
b = ''
def judge(row,col):
if 3<col<76 and 'a'<=a[row][col]<='z':
for i in [col-3,col-2,col-1,col+1,col+2,col+3]:
if not('A'<=a[row][i]<='Z'):
return False
try :
if 'A'<=a[row][col-4]<='Z':
return False
except:pass
try :
if 'A'<=a[row][col+4]<='Z':
return False
except:pass
return True
return False
for i in range(len(a)):
for j in range(len(a[0])-1):
if judge(i,j):
b+=a[i][j]
text.close()
得到结果
>>> print(b)
linkedlist
4.
点击图片进入页面nothing= 12345,写一个循环读取页面数字进入下一个页面import requests
hea = {'User-Agent':'Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.118 Safari/537.36'}
num=12345
a=[]
while(1):
html = requests.get('http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=%d'%num,headers = hea)
html.encoding = 'utf-8'
num = int(html.text.split(' ')[-1])
a.append(num)
中途会报错:
Traceback (most recent call last):
File "C:/Users/Administrator/Documents/pythonchallenge/5.py", line 17, in <module>
num = int(html.text.split(' ')[-1])
ValueError: invalid literal for int() with base 10: 'going.'
此时,num为 a[-1] = 16044,进入页面,显示 “Yes. Divide by two and keep going.”
修改num = 8022,继续循环,最后报错:
Traceback (most recent call last):
File "C:/Users/Administrator/Documents/pythonchallenge/5.py", line 18, in <module>
num = int(html.text.split(' ')[-1])
ValueError: invalid literal for int() with base 10: 'peak.html'
答案为 'peak.html',此时 a[-1] = 66831
5.
http://www.pythonchallenge.com/pc/def/peak.html
毫无头绪,看页面源码,进入banner.p 页面,乱七八糟 -_-#不知道是啥,经过一系列操作得知需要学习pickle模块
使用的python3,在 load() 解析时会报错the STRING opcode argument must be quoted pickle,是由于版本不兼容
使用python2.7,可以解码出一个二位列表,列表中是元组,(字符,个数),解析后得到答案channel
import requests
import pickle
hea = {'User-Agent':'Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.118 Safari/537.36'}
html = requests.get('http://www.pythonchallenge.com/pc/def/banner.p',headers = hea)
html.encoding = 'utf-8'
##print(html.text)
a = open('5.p','w')
a.write(html.text)
a.close()
b = open('5.p','r')
data = pickle.load(b)
b.close
str = ‘’
for i in data:
for j in i:
str+=j[0]*j[1]
str+='\n'
print (str)
6.
http://www.pythonchallenge.com/pc/def/channel.html
网页开头
<html> <!-- <-- zip -->
网址使用 : http://www.pythonchallenge.com/pc/def/channel.zip
下载了一个压缩包 : channel.zip
打开后发现一个readme,得到提示 :
welcome to my zipped list.
hint1: start from 90052
hint2: answer is inside the zip
类似题4,循环读取得到的数值 并打开响应文件 , 报错后读取最后一次正确数值对应的文件
import zipfile
z = zipfile.ZipFile('channel.zip')
nothing = '90052'
a = []
try:
while(1):
c = z.open(nothing+'.txt','r')
nothing = str(c.readline(),encoding = 'UTF-8').split(' ')[-1]
a.append(nothing)
except:
c = z.open(a[-2]+'.txt','r')
print(c.readline())
得到结果 : Collect the comments.
需要收集压缩文件的注释 =_=# , 经过一波精彩的操作之后,我知道可以通过
z.getinfo('90052.txt').comment
来得到注释信息 , 结果是 :
b'*'
修改前面的代码,加入注释收集:
import zipfile z = zipfile.ZipFile('channel.zip') nothing = '90052' a = [] b = [] d = '' try: while(1): c = z.open(nothing+'.txt','r') b.append(z.getinfo(nothing+'.txt').comment) nothing = str(c.readline(),encoding = 'UTF-8').split(' ')[-1] a.append(nothing) except: c = z.open(a[-2]+'.txt','r') print(c.readline()) for i in b: d += str(i,encoding='UTF-8')
>>> print(d) **************************************************************** **************************************************************** ** ** ** OO OO XX YYYY GG GG EEEEEE NN NN ** ** OO OO XXXXXX YYYYYY GG GG EEEEEE NN NN ** ** OO OO XXX XXX YYY YY GG GG EE NN NN ** ** OOOOOOOO XX XX YY GGG EEEEE NNNN ** ** OOOOOOOO XX XX YY GGG EEEEE NN ** ** OO OO XXX XXX YYY YY GG GG EE NN ** ** OO OO XXXXXX YYYYYY GG GG EEEEEE NN ** ** OO OO XX YYYY GG GG EEEEEE NN ** ** ** **************************************************************** **************************************************************
英语不好,查了一下 hockey : n. 曲棍球;冰球
7.it's in the air. look at the letters.
看不懂,放弃治疗!!!明天再做