Python挑战游戏( PythonChallenge)闯关之路Level- 3
来源:互联网 发布:科讯cms从入门到精通 编辑:程序博客网 时间:2024/06/06 07:46
闯关过程
闯关入口:http://www.pythonchallenge.com/pc/def/equality.html
根据页面提示, 应该是寻找字符串, 一个小写字母两边都是3个大写字母,类似如下:
bXXXtXXXb
即 b 是任意非大写字母
X 是大写字母
t 就是要找的目标字母
import urllib2import HTMLParserimport refrom string import maketrans,translate,lowercase,punctuationdef get_html_Pages(url):try: headers = {'User-Agent':'Mozilla/5.0 (Windows NT 6.2; rv:16.0) Gecko/20100101 Firefox/16.0'}#构建请求的request request=urllib2.Request(url,headers=headers) #利用urlopen获取页面代码 response=urllib2.urlopen(request) #将页面转化为UTF-8编码格式 html=response.read().decode('utf-8')html=HTMLParser.HTMLParser().unescape(html)#处理网页内容, 可以将一些html类型的符号如" 转换回双引号return html #捕捉异常,防止程序直接死掉 except urllib2.URLError,e:print u"连接失败,错误原因",e.reason return None except urllib2.HTTPError,e: print u"连接失败,错误原因:%s " % e.code return None def level3(self):level3_url='http://www.pythonchallenge.com/pc/def/equality.html'html=get_html_Pages(level3_url)#获取网页内容tips_string_pattern=re.compile('<!--(.*?)-->',re.S)#定义匹配规则,获取网页中注释的内容 tips_string=re.search(tips_string_pattern,html).group(1).strip()#匹配规则, 一个小写字母两边有且都有3个大写字母find_pattern=re.compile(r'[^A-Z][A-Z]{3}([a-z])[A-Z]{3}[^A-Z]')print ''.join(re.findall(find_pattern,tips_string))
linkedlist
0 0
- Python挑战游戏( PythonChallenge)闯关之路Level- 3
- Python挑战游戏( PythonChallenge)闯关之路Level 0
- Python挑战游戏( PythonChallenge)闯关之路Level- 1
- Python挑战游戏( PythonChallenge)闯关之路Level- 2
- Python挑战游戏( PythonChallenge)闯关之路Level- 4
- Python挑战游戏( PythonChallenge)闯关之路Level- 5
- Python挑战游戏( PythonChallenge)闯关之路Level- 6
- PythonChallenge 挑战之路 Level-3
- PythonChallenge 挑战之路 Level-0
- PythonChallenge 挑战之路 Level-1
- PythonChallenge 挑战之路 Level-2
- PythonChallenge 挑战之路 Level-4
- PythonChallenge 挑战之路 Level-5
- PythonChallenge 挑战之路 Level-6
- PythonChallenge 挑战之路 Level-7
- PythonChallenge 挑战之路 Level-8
- PythonChallenge 挑战之路 Level-9
- PythonChallenge 挑战之路 Level-10
- 剑指offer-62.二叉搜索树的第k个结点
- java 伪随机数安全性
- CUDA动态库封装以及调用
- keras环境配置小问题总结
- 3781: 小B的询问
- Python挑战游戏( PythonChallenge)闯关之路Level- 3
- 百练OJ1088题 滑雪 Python
- 接入SDK
- android /linux usb typec 插拔以及主从机识别过程
- Hadoop MapReduceV2(Yarn) 框架简介
- 深入理解 JavaScript 中的函数
- wireshark常用选项与功能总结【10分钟成为抓包大师】
- 网络流的五月
- 查找(3)---二叉查找树