题目地址:http://sec.hdu.edu.cn/question/web/1047/
题目如下:
给你2秒钟的时间,告诉我下面这坨字符中有多少个s,多少个e,多少个c,多少个l,多少个a和多少个b, 把这些数字串成一个字符串提交一下。只能用脚本来完成了。
看一下题目的源代码:
写出对应的python脚本:
# coding=UTF-8 import urllib,urllib2,requests from bs4 import BeautifulSoup url = "http://sec.hdu.edu.cn/question/web/1047/" head_info={ 'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64; rv:47.0) Gecko/20100101 Firefox/47.0', 'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'Accept-Language':'zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3', 'Accept-Encoding':'gzip, deflate', 'Cookie':'JSESSIONID=FA2540037BC70E131CC2837234D92EAD', 'Connection':'keep-alive', 'Cache-Control':'max-age=0', } r=requests.get(url,headers=head_info).content soup=BeautifulSoup(r,'lxml') str=soup.findAll("pre") a=str[0].contents Unicode2str=a[0].encode("utf-8") ln=len(Unicode2str) s=0 e=0 c=0 l=0 a=0 b=0 for i in range(ln): if (Unicode2str[i] == 's' ): s=s+1 elif (Unicode2str[i]== 'e' ): e=e+1 elif (Unicode2str[i] == 'c' ): c=c+1 elif (Unicode2str[i]== 'l' ): l=l+1 elif (Unicode2str[i] == 'a' ): a=a+1 elif (Unicode2str[i]=='b'): b=b+1 else: continue value='%d' %s +'%d' %e +'%d' %c +'%d' %l +'%d' %a +'%d' %b getdata={'ans':value} gdata=urllib.urlencode(getdata) url2=url+'?'+gdata print url2 r = requests.get(url2,headers=head_info).content print r
运行,得到flag。