zoukankan      html  css  js  c++  java
  • 使用python 3.x 对pythonchallenge-----17的解答过程

    pythonchallenge-17地址 : http://www.pythonchallenge.com/pc/return/romance.html

    题目解析: 图片嵌入了第4题的图片,图片有很多cookie
    所以需要先获取cookie,页面cookie信息 info : you+should+have+followed+busynothing...
    将第4题的后缀改为busynothing 然后在获取
    代码如下:
    #http://www.pythonchallenge.com/pc/return/romance.html username : huge password : file
    #you+should+have+followed+busynothing...
    #%B2hs%C0%9Fy%E3D%BC%8B%EB%B8i%98lu2o%5D%C9%A0
    from urllib import request,response,parse
    import urllib
    from http import cookies,cookiejar
    import bz2
    
    postdata= urllib.parse.urlencode({
        'Username': 'huge',
        'Password': 'file'
    }).encode('utf-8')
    
    header = {
        "Accept":"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
        #"Accept-Encoding":"	gzip, deflate, br",
        "Accept-Language":"zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3",
        "Authorization": "Basic aHVnZTpmaWxl",#授权头,账号密码
        "Connection":"keep-alive",
        "Host":"www.pythonchallenge.com",
        "User-Agent":"Mozilla/5.0 (Windows NT 6.1; WOW64; rv:32.0) Gecko/20100101 Firefox/55.0"
    }
    url = r'http://www.pythonchallenge.com/pc/return/romance.html'
    url_linkedlist = r'http://www.pythonchallenge.com/pc/def/linkedlist.php?busynothing='
    url_linkedlist1 = r'http://www.pythonchallenge.com/pc/def/linkedlist.php?busynothing=12345'
    
    
    def getcookie(req):
        #声明一个CookieJar对象实例来保存cookie
        ck = cookiejar.CookieJar()
        #利用urllib.request库的HTTPCookieProcessor对象来创建cookie处理器,也就CookieHandler
        handler = request.HTTPCookieProcessor(ck)
        #通过CookieHandler创建opener
        opener = request.build_opener(handler, request.HTTPHandler)
        r = opener.open(req)
        htmltext = r.read().decode()
        nothing =htmltext.split(' ')[-1]
        print(htmltext + "-------" + nothing)
    
        opener.close()
        for item in ck:
            #return (item.name + " : " + item.value)
            return (item.value,nothing)
    
    
    nothing = '12345'
    list = []
    for i in range(400):
    
        if nothing != 'it.':
            req = request.Request(url_linkedlist+nothing,postdata,header)
            reqcookie = getcookie(req)
            print(i,end=" : ")
            nothing = reqcookie[1]
            list.append(reqcookie[0])
    
    answer = "".join(list)
    print("")
    print(bz2.decompress(parse.unquote_to_bytes(answer.replace('+', '%20'))).decode('ascii'))
    
     
  • 相关阅读:
    c# datagridview 设置某行不可见解决办法
    MessageBox, MessageBoxBurttons, MessageBoxIcon 详细解析
    c# 项目带皮肤一起打包发布解决办法
    Winform DataGridView CheckBoxColumn c# 单选 解决方案
    机器学习 课程笔记
    机器学习-review-1 线性回归
    Office升级到2013版后无法登录微软账号问题
    Address already in use: make_sock: could not bind to address 0.0.0.0:80
    PHP的数组排序函数
    事件与委托例子
  • 原文地址:https://www.cnblogs.com/yinsjun/p/7576307.html
Copyright © 2011-2022 走看看