欢迎使用CSDN-markdown编辑器

来源:互联网 发布:淘宝卖家平台软件 编辑:程序博客网 时间:2024/04/28 19:34

爬取知乎10个主题的各5K个问答

代码块

代码块语法遵循标准markdown代码,例如:

# -*- coding:utf-8 -*-import urllibimport urllib2import reimport hashlibimport cookielibimport webbrowserimport requestsfrom bs4 import BeautifulSoupimport codecsdef get_question_content(topic_number):    file_bath = 'f:/' + str(topic_number) + '.txt'    f = codecs.open(file_bath,'w','utf-8')    global question_url    global question_content    index_question_url = 1    for question_number in question_url[topic_number]:        url = 'http://www.zhihu.com/question/' + question_number        s = requests.session()        content = s.get(url).text        pattern_title = re.compile('<h2 class="zm-item-title zm-editable-content">(.*?)</',re.S)        titles = re.findall(pattern_title,content)        for title in titles:            f.write('title'+str(index_question_url)+':'+"\r\n")            f.write(title+"\r\n")            print title        pattern = re.compile('<.*?zm-editable-content clearfix">(.*?)</div>',re.S)        items = re.findall(pattern,content)        index_question_content = 1        for item in items:            if index_question_content < 11:                print str(topic_number)+'.'+str(len(question_content[topic_number]))                p = re.compile('<(.*?)>',re.S)                item = p.sub('',item)                question_content[topic_number].append(item)                f.write('answer'+str(index_question_content)+':'+"\r\n")                f.write(item+"\r\n")            index_question_content = index_question_content + 1        index_question_url = index_question_url + 1    f.close()def get_question_url (topic_url,index_topic_codes):    global question_url    s = requests.session()    content = s.get(topic_url).text    pattern = re.compile('question_link.*?href="/question/(.*?)">(.*?)</',re.S)    items = re.findall(pattern,content)    index_question_number = 0    for item in items:        if item[0] not in question_url[index_topic_codes]:            question_url[index_topic_codes].append(item[0])topic_codes = ['19551424','19564408','19551137','19556664','19570005','19552330','19553713','19556784','19554827','19552981']#政治0,爱情1,美食2,科技3,校园4,程序员5,书籍6,电影推荐7,体育8,经济9question_url = [[] for y in range(10)]index_topic_codes = 0for topic_code in topic_codes:    for page_code in range(50):        topic_url = 'http://www.zhihu.com/topic/' + topic_code + '/top-answers?page=' + str(page_code+1)        get_question_url(topic_url,index_topic_codes)    index_topic_codes = index_topic_codes + 1for i in range(10):    print len(question_url[i])question_content = [[] for x in range(10)]for i in range(10):    get_question_content(i)... prompt'''

脚注

生成一个脚注1.

目录

[TOC]来生成目录:

      • 代码块
      • 脚注
      • 目录
      • 数学公式
      • UML 图
    • 离线写博客
    • 浏览器兼容

数学公式

使用MathJax渲染LaTex 数学公式,详见math.stackexchange.com.

  • 行内公式,数学公式为:Γ(n)=(n1)!nN
  • 块级公式:

x=b±b24ac2a

更多LaTex语法请参考 这儿.

UML 图:

可以渲染序列图:

Created with Raphaël 2.1.0张三张三李四李四嘿,小四儿, 写博客了没?李四愣了一下,说:忙得吐血,哪有时间写。

或者流程图:

Created with Raphaël 2.1.0开始我的操作确认?结束yesno
  • 关于 序列图 语法,参考 这儿,
  • 关于 流程图 语法,参考 这儿.

离线写博客

即使用户在没有网络的情况下,也可以通过本编辑器离线写博客(直接在曾经使用过的浏览器中输入write.blog.csdn.net/mdeditor即可。Markdown编辑器使用浏览器离线存储将内容保存在本地。

用户写博客的过程中,内容实时保存在浏览器缓存中,在用户关闭浏览器或者其它异常情况下,内容不会丢失。用户再次打开浏览器时,会显示上次用户正在编辑的没有发表的内容。

博客发表后,本地缓存将被删除。 

用户可以选择 把正在写的博客保存到服务器草稿箱,即使换浏览器或者清除缓存,内容也不会丢失。

注意:虽然浏览器存储大部分时候都比较可靠,但为了您的数据安全,在联网后,请务必及时发表或者保存到服务器草稿箱

浏览器兼容

  1. 目前,本编辑器对Chrome浏览器支持最为完整。建议大家使用较新版本的Chrome。
  2. IE9以下不支持
  3. IE9,10,11存在以下问题
    1. 不支持离线功能
    2. IE9不支持文件导入导出
    3. IE10不支持拖拽文件导入


  1. 这里是 脚注内容. ↩
0 0
原创粉丝点击