抓取 题目描述 生成 解题报告 模板 python
2017-02-03 23:42
417 查看
BGround
偷懒是人类进步的阶梯!!瞎搞是自然选择的必然!!
这绝对是我写过最丑的python代码,但是的确能用,忍忍看吧
Code
# -*- coding: utf-8 -*- import requests, time, re import HTMLParser def getPage(html, url, headers, params = {}, timeout = 5, verify = True): response = html.get(url = url, headers = headers, params = params, timeout = timeout, verify = verify) page = response.content return page def search(string, page, flags = 0): pattern = re.compile(string, flags = flags) results = re.findall(pattern, page) return results def format(string): results = HTMLParser.HTMLParser().unescape(re.compile(r'<[^>]+>', re.S).sub('', re.sub('</strong>|</h2>', '\n---\n', re.sub('<strong>|<h2>', '\n##', string.decode('UTF-8'))))) return results def main(): html = requests.session() headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.22 Safari/537.36 SE 2.X MetaSr 1.0'} probid = raw_input('id: ') url = 'https://www.luogu.org/problem/show?pid=%s#sub' % probid PD = search(r"<div class=\"lg-article am-g\">(.+?)<div class=\'lg-article-sub am-g\' id=\"sub\"></div>", getPage(html, url, headers), flags = re.S)[0] with open('/home/olahiuj/文档/progs/oi/luogu%s.cpp' % probid, 'r') as file: content = ''' %s ## Analysis --- ## Code --- ` `` %s ` `` ''' % (re.sub(' ', '', format(PD).encode('UTF-8')), file.read().encode('UTF-8')) with open('/home/olahiuj/文档/LPD/luogu%s.md' % probid, 'w') as file: file.write(content) print 'Problem %s is Done!' % probid if __name__ == '__main__': main()
相关文章推荐
- 最小生成树,POJ和HDU几道题目的解题报告(基于自己的模板)
- 最小生成树,POJ和HDU几道题目的解题报告(基于自己写的模板)
- Pku acm 1258 Agri-Net数据结构题目解题报告(四) ----最小生成树:prim算法
- CCF CSP 201509-3 模板生成系统 解题报告
- csp解题报告 模板生成系统
- Pku acm 2075 Tangled in Cables数据结构题目解题报告(十一)最小生成树:prim算法&amp;amp;二叉查找树
- python 报告模板生成笔记一
- Pku acm 2485 Highways数据结构题目解题报告(三) ----最小生成树:prim算法
- Pku acm 1861 NetWork 数据结构题目解题报告(二) ----最小生成树:prim算法&amp;amp;Kruskal算法
- CCF CSP 201509-3 模板生成系统 解题报告
- Pku acm 2075 Tangled in Cables数据结构题目解题报告(十一)最小生成树:prim算法&amp;amp;二叉查找树
- Pku acm 1157 LITTLE SHOP OF FLOWERS 动态规划题目解题报告(十四)
- Pku acm 3253 Fence Repair 数据结构题目解题报告(一) ----哈夫曼数
- Pku acm 2253 Frogger数据结构题目解题报告(六)—单源最短路径:Dijkstra算法
- Pku acm 3278 Catch That Cow数据结构题目解题报告(五) ----树的BFS
- Pku acm 2192 Zipper 动态规划题目解题报告(九)
- Pku acm 2492 A Bug's Life数据结构题目解题报告(十)---- 并查集的应用
- Pku acm 1125 Stockbroker Grapevine 动态规划题目解题报告(十九)
- Pku acm 1160 post office 动态规划题目解题报告(十八)
- Pku acm 1125 Stockbroker Grapevine 数据结构题目解题报告(八)---- 弗洛伊德(floyd)算法