使用python 3.x 对pythonchallenge-----4的解答过程

pythonchallenge-4地址 : http://www.pythonchallenge.com/pc/def/linkedlist.php图片如下:
题目解析:通过页面源代码解析,要打开链接http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=12345,然后获取nothing值,一直循环直到得出答案
解题过程:
from urllib import request,parse
import re

url = r‘http://www.pythonchallenge.com/pc/def/linkedlist.php?‘

headers = {
    ‘User-Agent‘: r‘Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) ‘
                    r‘Chrome/45.0.2454.85 Safari/537.36 115Browser/6.0.3‘,
    ‘Connection‘: ‘keep-alive‘
}
data = {}
data[‘nothing‘] = "12345"

def getnothing(url,data,headers):
    data = parse.urlencode(data)
    url = url + data
    req = request.Request(url,headers=headers)
    page = request.urlopen(req).read().decode(‘utf-8‘)
    return page

for i in range(251):
    htmlstr = getnothing(url=url,data=data,headers=headers)
    pattern = re.compile(‘\d+‘)
    nothingnum = re.findall(pattern,htmlstr)
    if nothingnum:
        data[‘nothing‘] = nothingnum[0]
        if len(nothingnum)>1:
            data[‘nothing‘] = nothingnum[1]
    else:
        data[‘nothing‘] = str(int(data[‘nothing‘])/2)
    print(str(i) + " ---- " + htmlstr)
    print(data[‘nothing‘])

答案:

250 ---- peak.html

心得:在第85次和第140次的时候分别有个小坑

85 ---- Yes. Divide by two and keep going
...
...
...
140 ---- There maybe misleading numbers in the
text. One example is 82683. Look only for the next nothing and the next nothing is 63579
 
 
时间: 2024-07-29 08:06:04

使用python 3.x 对pythonchallenge-----4的解答过程的相关文章

Python 语言搭建SELENIUM测试环境,搭建过程记录。

第一步,安装Python: 第二步,安装SetupTools: 第三步,安装Pip: 第四步,安装selenium(for python) 第五步,新建第一个基于Firefox的测试用例 上述 只是步骤,具体内容,明天补充,睡觉 咯--- Python 语言搭建SELENIUM测试环境,搭建过程记录.

使用python 3.x 对pythonchallenge-----14的解答过程

pythonchallenge-14地址 : http://www.pythonchallenge.com/pc/return/italy.html 题目解析:获取的信息有 ①图片是一个便便一样的面包 ②源代码中有信息如下 <!-- remember: 100*100 = (100+99+99+98) + (... --> ③页面存在一个wire.png的图片,解析后得出图片的像素未1*10000 分析题意,按2中的方法将3中的图片分解,然后按一图片意思,旋转着保存在图片中..如:第100个像

使用python 3.x 对pythonchallenge-----12的解答过程

pythonchallenge-10地址 : http://www.pythonchallenge.com/pc/return/evil.html图片如下: 题目解析: 查看源代码,图片地址为evil1.jpg 这个有点奇怪试着用evil2.jpg访问,出现一个图片,图片内容为not jpg --.gfx于是用evil2.gfx 访问链接,打开是一个乱码文件,用IE下载gfx文件题目的意思就是将gfx文件分为5份,然后在图片中显示 解题过程: # coding = utf-8 from PIL

大概看了一天python request源码。写下python requests库发送 get,post请求大概过程。

python requests库发送请求时,比如get请求,大概过程. 一.发起get请求过程:调用requests.get(url,**kwargs)-->request('get', url, **kwargs)-->session.request(method="get", url=url, **kwargs)-->session.send(request, **kwargs)-->adapter.send(request, **kwargs)-->

使用python 3.x 对pythonchallenge-----5的解答过程

pythonchallenge-5地址 : http://www.pythonchallenge.com/pc/def/peak.html图片如下: 题目解析:源代码中有个链接<peakhell src="banner.p"/>,下载一个banner.p的文件.根据题目的意思就是要使用pickle.load(),将下载的文件进行反序列化 解题过程: import pickle path = r"./other/banner.p" f = open(pat

使用python 3.x 对pythonchallenge-----1的解答过程

pythonchallenge-1地址 : http://www.pythonchallenge.com/pc/def/274877906944.html图片如下: 题目解析:看图也不懂是什么意思,于是看一下攻略.题目意思:把每个字符位移两次,例如:K→M解题过程: import re def charshitf(aa): p1=re.compile('[a-x]') if p1.match(aa): return chr(ord(aa)+2) elif aa == 'y': return 'a

使用python 3.x 对pythonchallenge-----9的解答过程

pythonchallenge-9地址 : http://www.pythonchallenge.com/pc/return/good.html图片如下: 题目解析:源代码提示first+second=? 根据图片的提示,将first和second里面的数,当分别当图像坐标处理,然后将图片连起来看 解题过程: first = [146,399,163,403,170,393,169,391,166,386,170,381,170,371,170,355,169,346,167,335,170,3

python学习第四节 迭代器 生成器 面向过程编程

1:什么是迭代 可以直接作用于for循环的对象统称为可迭代对象(Iterable). 可以被next()函数调用并不断返回下一个值的对象称为迭代器(Iterator). 所有的Iterable均可以通过内置函数iter()来转变为Iterator. 对迭代器来讲,有一个__next()就够了.在你使用for 和 in 语句时,程序就会自动调用即将被处理的对象的迭代器对象,然后使用它的next__()方法,直到监测到一个StopIteration异常. >>> L = [1,2,3]>

pycharm+PyQt5+python最新开发环境配置,踩坑过程详解

Python 3.6https://www.python.org/downloads/windows/========================================PyQt5 pip3 install  PyQt5 -i https://pypi.tuna.tsinghua.edu.cn/simple 安装图形界面开发工具Qt Designerpip3 install  PyQt5-tools -i https://pypi.tuna.tsinghua.edu.cn/simpl