PythonChallenge Level 0: http://www.pythonchallenge.com/pc/def/0.html
计算 2 的 38 次幂 将得到的结果替换URL中数字0
print 2**38
PythonChallenge Level 1: http://www.pythonchallenge.com/pc/def/map.html
照笔记本中给出的规律解密图片下方给出的一串字符
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.
用到两个函数
Return a translation table suitable for passing to translate(), that will map each character in from into the character at the same position in to; from and to must have the same length.
##返回一个转换表 table( eg. 'A'-->'a', 'B'-->'b'), from 和 to 长度必须一致,在 from 中有的字符转换成 to 中对应位置的字符
string.translate(s, table[, deletechars])Delete all characters from s that are in deletechars (if present), and then translate the characters using table, which must be a 256-character string giving the translation for each character value, indexed by its ordinal. If table is None, then only the character deletion step is performed.
##按照转换表 table,对字符串 s 进行转换
import string #load the text 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. ''' #creat a translate table table = string.maketrans(string.ascii_lowercase, string.ascii_lowercase[2:] + string.ascii_lowercase[:2]) #apply the translation table on string print string.translate(text, table) # Or you can "print text.translate(table)"
if you don't know "string.ascii_lowercase[2:]", "string.ascii_lowercase[:2]", "string.ascii_lowercase", try to print it.
执行结果: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.(对Level 1 URL中 map 进行同样替换即可转至Level 2)
PythonChallenge Level 2: http://www.pythonchallenge.com/pc/def/ocr.html
网页的左下角还有几条提示
General tips:
- Use the hints. They are helpful, most of the times.
- Investigate the data given to you.
- Avoid looking for spoilers.
We saw the hint “but MABYE they are in the page source”
故执行: 右击网页 --> 查看网页源代码
找到了这一关的谜题: find rare characters in the mess below:
用到一个 str.isalpha() 函数,判断是否字母
str.isalpha()Return true if all characters in the string are alphabetic and there is at least one character, false otherwise.
For 8-bit strings, this method is locale-dependent.
import string mess = ''' #copy the mess from Level.2's page source ''' ans = '' for x in mess: if x.isaplha(): ans += x print ans
得到结果: equality
将其替换 Level 2 URL 中的 " ocr " 即转到level 3
PythonChallenge Level 3: http://www.pythonchallenge.com/pc/def/equality.html
网页左下角内容
To see the solutions to the previous level, replace pc with pcc, i.e. go to: http://www.pythonchallenge.com/pcc/def/equality.html
Join us on IRC: irc.freenode.net #pythonchallenge
网页左下角的内容与本题无关,但从句中'see the solutions to the previious level'中得到启发,同第二关一样查看了网页的源代码,其中果然给出了mess.
图片正下方提示
One small letter, surrounded by EXACTLY three big bodyguards on each of its sides.
一个小写字母两边都有三个大写字母,形如 XXXxXXX ,后经尝试并不能得到结果,搜索之,其他过关的人用来匹配的形式为 xXXXxXXXx ,虽然还没明白为何如此,但确实是到下一关的正确方向。
从给出的mess中找出xXXXxXXXx形式的字符,用到网页源代码获取模块Urllib2以及正则表达式re模块。
urllib2.urlopen(url[, data[, timeout[, cafile[, capath[, cadefault[, context]]]]])Open the URL url, which can be either a string or a Request object.
data may be a string specifying additional data to send to the server, or None if no such data is needed. Currently HTTP requests are the only ones that use data; the HTTP request will be a POST instead of a GET when the data parameter is provided. data should be a buffer in the standard application/x-www-form-urlencoded format. The urllib.urlencode() function takes a mapping or sequence of 2-tuples and returns a string in this format. urllib2 module sends HTTP/1.1 requests with Connection:close header included.
The optional timeout parameter specifies a timeout in seconds for blocking operations like the connection attempt (if not specified, the global default timeout setting will be used). This actually only works for HTTP, HTTPS and FTP connections.
If context is specified, it must be a ssl.SSLContext instance describing the various SSL options. See HTTPSConnection for more details.
The optional cafile and capath parameters specify a set of trusted CA certificates for HTTPS requests. cafile should point to a single file containing a bundle of CA certificates, whereas capath should point to a directory of hashed certificate files. More information can be found in ssl.SSLContext.load_verify_locations().
The cadefault parameter is ignored.
This function returns a file-like object with three additional methods:
- geturl() — return the URL of the resource retrieved, commonly used to determine if a redirect was followed
- info() — return the meta-information of the page, such as headers, in the form of an mimetools.Message instance (see Quick Reference to HTTP Headers)
- getcode() — return the HTTP status code of the response.
Raises URLError on errors.
Note that None may be returned if no handler handles the request (though the default installed global OpenerDirector uses UnknownHandlerto ensure this never happens).
In addition, if proxy settings are detected (for example, when a *_proxy environment variable like http_proxy is set), ProxyHandler is default installed and makes sure the requests are handled through the proxy.
Changed in version 2.6: timeout was added.
Changed in version 2.7.9: cafile, capath, cadefault, and context were added.
Return all non-overlapping matches of pattern in string, as a list of strings. The string is scanned left-to-right, and matches are returned in the order found. If one or more groups are present in the pattern, return a list of groups; this will be a list of tuples if the pattern has more than one group. Empty matches are included in the result unless they touch the beginning of another match.
New in version 1.5.2.
Changed in version 2.4: Added the optional flags argument.
import urllib2 import re import string text = urllib2.urlopen('http://www.pythonchallenge.com/pc/def/equality.html').read() matstr = re.findall(r'[a-z][A-Z]{3}[a-z][A-Z]{3}[a-z]', text) ans = '' i = 0 while i < len(matstr): ans += matstr[i][4] i += 1 print ans
基于找出的匹配字符需有意义的角度,最后的ans只提取了xXXXxXXXx形式中间的小写字母
代码运行结果为 linkedlist 按照前几题的经验,替换Level 3中equality回车得到提示“linkedlist.php”,按提示再次替换html为php即转至Level 4
PythonChallenge Level 4: http://www.pythonchallenge.com/pc/def/linkedlist.php
给了一幅没怎么看得懂的图,查看是否有隐藏提示于网页源代码中,右击-->查看网页源代码 如下
<html> <head> <title>follow the chain</title> <link rel="stylesheet" type="text/css" href="../style.css"> </head> <body> <!-- urllib may help. DON'T TRY ALL NOTHINGS, since it will never end. 400 times is more than enough. --> <center> <a href="linkedlist.php?nothing=12345"><img src="chainsaw.jpg" border="0"/></a> <br><br><font color="gold"></center> Solutions to previous levels: <a href="http://wiki.pythonchallenge.com/"/>Python Challenge wiki</a>. <br><br> IRC: irc.freenode.net #pythonchallenge </body> </html>
主题“follow the chain”,注释“ urllib may help. DON'T TRY ALL NOTHINGS, since it will never end. 400 times is more than enough.”,另分析源代码可知网页中图片添加了超链接herf="linkedlist.php?nothing=12345",返回点击图片得到文本提示"and the next nothing is 44827"。
综上分析明白了Level 4 题面要做的就是递归更换 网页图片超链接URL中的nothing值
import urllib2 import string urLstr = 'http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=' def get_Nothings(uid): if uid.isdigit(): text = urllib2.urlopen(urLstr+uid).read() # print text nextuid = '' for x in text: if x.isdigit(): nextuid += x # print urLstr + uid print urllib2.urlopen(urLstr+uid).read(),'\n' return get_Nothings(nextuid) else: pass get_Nothings("12345")
代码运行一小段时间出现非数字给出nothing值的情况,提示“Yes,Divide by two and keep going”
将在其前的nothing值 16044 除以 2 即 8022 作为代码中函数get_Nothings()的初始值继续运行。
最后得到Level 4的结果 peak.html 将其替换到URL中即转至Level 5
Level 5 :http://www.pythonchallenge.com/pc/def/peak.html
Level 5~10 解题过程会记录在我的下一篇博客中,谢谢!-------by 江南メ星
相关推荐
标题和描述均提到了"pythonchallenge level2官方方法集",这表明文章主要聚焦于Python Challenge网站上第二级挑战的官方解决策略集合。Python Challenge是一个知名的编程谜题网站,通过一系列精心设计的谜题来测试和...
response = requests.get('http://www.pythonchallenge.com/pc/return/level4.html') html_content = response.text ``` 在处理HTML内容时,可能需要用到`BeautifulSoup`库来解析和提取有用信息。 最后,逻辑思维...
在Python Challenge这个在线编程挑战网站上,第二题通常是一个引导初学者进入更复杂问题的起点。这个挑战旨在帮助用户提升Python编程技能,并了解如何利用Python解决实际问题。在这个题解中,我们将深入探讨如何解开...
response = requests.get('http://www.pythonchallenge.com/pc/return/level3.html') page_content = response.text ``` 2. **HTML解析**:接下来,你需要解析获取的HTML内容。Python的`BeautifulSoup`库可以...
在本题中,我们将深入探讨Python编程语言在解决在线挑战平台`www.pythonchallenge.com`上的第五个问题。这个挑战通常会涉及一系列的编程技巧、逻辑思维以及对Python库的运用。我们将通过分析提供的代码和注释,理解...
Google的Foobar挑战 Google Foobar是Google的秘密招聘挑战。 名称 水平 资料库链接 世界末日 1级 耗电 2级 为破坏做准备 2级 准备兔子的逃生 3级 燃油喷射完美 3级 世界末日燃料 3级 快来了 4级
Challenge-python-02-生成密码 属 回购 恩EL档案馆main.py completa LAfunción generate_password 。 反对与反抗之间的矛盾,反抗与反抗,反抗与反抗。 Debe tener entre 8和16 caracteres。 通过últimocorre el...
Gain a fundamental understanding of Python’s syntax and features with the second edition of Beginning Python, an up–to–date introduction and practical reference. Covering a wide array of Python–...
香紫苏: 没有虚拟现实,您可以在虚拟环境中使用Python,也可以在Python核心中使用Python Utiliza Python 3参数解析器¡ 重要提示皮斯塔斯Abre el archivo con“ encoding ='utf-8'”避难所错误: with open ( '...
挑战Python-01-Palíndromo Unpalíndromoes una palalabra o frase que puede leerse igual al derecho y alrevés,como“ oso”,“ ana”,“ amad la dama”等。 回购 完整的is_palindrome和相关脚本。 改正...
ultimately storing it in a database to form a knowledge base for use in information retrieval, question answering, and other upper-level applications. In this event extraction information management...
源代码可能包含了游戏逻辑的Python脚本,例如`game.py`,`level_generator.py`(用于生成关卡),以及可能的UI相关的脚本。 学习和理解这个项目,开发者可以深入了解如何在Python中构建交互式游戏,包括游戏规则...
数据融合matlab代码一个关于OMG情感挑战的项目2018 这是OMG情感挑战赛2018的代码存储库。 Arxiv纸: 先决条件 要运行此代码,您需要先安装...运行generate_audio_feature_utterance_level.py :提取。 运行generate_wo
Google_foobar_level1 Google Foobar挑战是公司秘密招募全球顶级程序员和开发人员的过程。 众所周知,此过程雇用了Google的几名开发人员。 挑战包括五个级别,共有九个问题,难度级别在每个级别上都会增加。 在此...
NTIRE 2020 NonHomogeneous Dehazing Challenge (CVPR Workshop 2020)第一个解决方案。 环境: Ubuntu16.04 Python3.6 英伟达 GPU+CUDA8 依存关系: 预训练模型==0.7.4 火炬视觉==0.2.1 火炬==0.4.1 tqdm ...
computation graph, either in Python for simplicity, or in C to overcome the Python overhead, either for the CPU or for the GPU. Also, introduces the basic concept of parallel programming for GPU. ...
数据融合matlab代码一个关于OMG情感挑战的项目2018 这是OMG情感挑战赛2018的代码存储库。 Arxiv纸: 先决条件 要运行此代码,您需要先安装...运行generate_audio_feature_utterance_level.py :提取。 运行generate_wo
See how to use Kali Linux at an advanced level Understand the exploitation of Windows kernel drivers Understand advanced Windows concepts and protections, and how to bypass them using Kali Linux ...
L4DC2021(可能指Level 4 Data Challenge 2021)是一个相关的数据挑战或研讨会,其代码存储库包含了用于处理和分析此类数据的工具和算法。 【描述】"V2V流量预测"是利用V2V通信技术收集的数据来预测未来的交通流量...