{"id":907,"date":"2017-12-20T09:29:38","date_gmt":"2017-12-20T01:29:38","guid":{"rendered":"http:\/\/www.rain1024.com\/?p=907"},"modified":"2023-08-07T20:57:26","modified_gmt":"2023-08-07T12:57:26","slug":"article109","status":"publish","type":"post","link":"http:\/\/rain1024.com\/index.php\/2017\/12\/20\/article109\/","title":{"rendered":"CSDN\u4e2a\u4eba\u535a\u5ba2\u9605\u8bfb\u8bc4\u8bba\u4fe1\u606f\u7684\u722c\u53d6"},"content":{"rendered":"<h1>CSDN\u4e2a\u4eba\u535a\u5ba2\u9605\u8bfb\u8bc4\u8bba\u4fe1\u606f\u7684\u722c\u53d6<\/h1>\n<h3>\u7528\u6765\u722c\u53d6CSDN\u4e0a\u4e2a\u4eba\u535a\u5ba2\u7684\u4fe1\u606f\uff0c\u5305\u62ec\u9605\u8bfb\u6b21\u6570\uff0c\u8bc4\u8bba\u6570\u7b49\u7b49<\/h3>\n<h1>\u56e0\u4e3aCSDN\u66f4\u6362\u4e86\u754c\u9762\uff0c\u539f\u6765\u7684\u722c\u866b\u5df2\u7ecf\u5931\u6548\uff0c\u6240\u4ee5\u6211\u91cd\u65b0\u5199\u4e86\u4e00\u4e2a\u722c\u866b\uff0c\u53ef\u4ee5\u7cbe\u51c6\u7684\u722c\u53d6\u5230\u6bcf\u7bc7\u6587\u7ae0\u9605\u8bfb\u6b21\u6570\u548c\u8bc4\u8bba\u6b21\u6570\u7684\u53d8\u5316\uff0c\u5e76\u5c06\u603b\u7ed3\u51fa\u6765\u7684\u4fe1\u606f\u53d1\u9001\u5230\u90ae\u7bb1\u91cc\uff0c<\/h1>\n<h1>\u9879\u76ee\u4e2d\u6709\u4e24\u4e2a\u6587\u4ef6\uff0ccsdn_old.py\u662f\u65e7\u7248CSDN\u754c\u9762\u7684\u722c\u866b\uff0c\u4f7f\u7528\u4e86BeautifulSoup\u6765\u8fdb\u884c\u722c\u53d6\u4fe1\u606f\uff0c\u5b83\u7684\u529f\u80fd\u4e5f\u662f\u5c06\u6bcf\u65e5\u535a\u5ba2\u4fe1\u606f\u7684\u53d8\u5316\u503c\u603b\u7ed3\u4e0b\u6765\u53d1\u9001\u5230\u90ae\u7bb1\u91cc\uff0ccsdn_new.py\u662f\u65b0\u7248\u7684\u722c\u866b\uff0c\u5168\u90e8\u4f7f\u7528re\u6765\u63d0\u53d6\u4fe1\u606f\uff0c\u5e76\u6dfb\u52a0\u4e86\u8bc4\u8bba\u6b21\u6570\u7684\u68c0\u6d4b\u3002<\/h1>\n<h1>\u4ee3\u7801\u8bf4\u660e\uff1a<\/h1>\n<h2>1.\u9700\u8981\u914d\u7f6e\u5bf9\u5e94\u7684\u6570\u636e\u5e93\u6587\u4ef6\uff0c\u56e0\u4e3a\u91cc\u9762\u4fdd\u5b58\u4e86\u535a\u5ba2\u524d\u4e00\u65e5\u7684\u5168\u90e8\u4fe1\u606f<\/h2>\n<h2>2.\u9700\u8981\u53d1\u9001\u90ae\u4ef6\uff0c\u5fc5\u987b\u6709\u5bf9\u5e94\u7684\u90ae\u7bb1\u8d26\u53f7\u548c\u5bc6\u7801\u624d\u80fd\u4f7f\u7528<\/h2>\n<h2>3.\u6211\u7684\u4ee3\u7801\u662f\u653e\u5230\u670d\u52a1\u5668\u4e0a\u6bcf\u5929\u5b9a\u65f6\u8fd0\u884c\u7684\uff0c\u6ca1\u6709\u670d\u52a1\u5668\u7684\u540c\u5b66\u53ef\u4ee5\u8054\u7cfb\u6211\uff0c\u4e5f\u53ef\u4ee5\u653e\u5230\u6211\u7684\u670d\u52a1\u5668\u4e0a\u3002<\/h2>\n<h2>\u5b9e\u73b0\u6548\u679c<\/h2>\n<p><img decoding=\"async\" src=\"http:\/\/cos.rain1024.com\/blog\/python\/python48.jpg\" alt=\"\" \/><\/p>\n<h1><a href=\"https:\/\/gitee.com\/rainweb\/CSND\">Gitee\u4e0a\u7684\u5730\u5740https:\/\/gitee.com\/rainweb\/CSND<\/a><\/h1>\n<h1>csdn_new.py<\/h1>\n<pre><code>#-*- coding=utf8 -*-\nimport sys\nreload(sys)\nsys.setdefaultencoding( \"utf-8\" )\nimport urllib2\nimport re\nimport MySQLdb\nimport datetime\nimport time\nimport smtplib\nfrom email.mime.text import MIMEText\nfrom email.header import Header\ndef email(text ,toemail):\n    sender = \"\"   #\u53d1\u9001\u65b9\u7684\u90ae\u7bb1\n    password = \"\"         #\u90ae\u7bb1\u7684\u6388\u6743\u7801\n    receiver = toemail  #\u63a5\u6536\u65b9\u7684\u90ae\u7bb1\n    data_time = time.strftime(\"%Y-%m-%d\")\n    subject = data_time + \"\u65e5\u7684CSDN\u535a\u5ba2\u62a5\u544a\"   #title\u90ae\u4ef6\u6807\u9898\n    words = text   #text\u90ae\u4ef6\u5185\u5bb9\n    smtpserver = 'smtp.exmail.qq.com'\n    msg = MIMEText(words, 'plain', 'utf-8')#\u4e2d\u6587\u9700\u53c2\u6570\u2018utf-8'\uff0c\u5355\u5b57\u8282\u5b57\u7b26\u4e0d\u9700\u8981\n    msg['Subject'] = Header(subject, 'utf-8') #\u90ae\u4ef6\u6807\u9898\n    msg['from'] = sender #\u53d1\u4fe1\u4eba\u5730\u5740\n    msg['to'] = receiver #\u6536\u4fe1\u4eba\u5730\u5740\n    smtp = smtplib.SMTP_SSL(\"smtp.exmail.qq.com\", 465)\n    smtp.connect('smtp.exmail.qq.com')\n    smtp.login(sender, password)\n    smtp.sendmail(sender, receiver, msg.as_string())\n    smtp.quit()\n    print data_time + \"\u7684\u90ae\u4ef6\u53d1\u9001\u6210\u529f!\"\n# \u5b9e\u73b0\u4e0b\u8f7dHTML\u7f51\u9875\u6e90\u7801\u7684\u51fd\u6570\uff0curl\u4e3a\u5730\u5740\ndef DownLoad_Html(url):\n    try:\n        html = urllib2.urlopen(url).read()\n    except urllib2.URLError as e:\n        print \"error\"\n        print e.code  # \u53ef\u4ee5\u6253\u5370\u51fa\u6765\u9519\u8bef\u4ee3\u53f7\u5982404\u3002\n        print e.reason  # \u53ef\u4ee5\u6355\u83b7\u5f02\u5e38\n        html = None\n    return html\ndef operator_SQL(flag,update=None):\n    # \u5c06\u83b7\u53d6\u7684\u6570\u636e\u5b58\u5165\u6570\u636e\u5e93\u4e2d\n    try:\n        conn = MySQLdb.connect(\n            host='127.0.0.1',\n            port=3306,\n            user='root',\n            passwd='root',\n            # user='',\n            # passwd='',\n            db='test',\n            charset='utf8',\n        )\n    except:\n        conn = MySQLdb.connect(\n            host='127.0.0.1',\n            port=3306,\n            # user='root',\n            # passwd='root',\n            user='',\n            passwd='',\n            db='test',\n            charset='utf8',\n        )\n    cur = conn.cursor()\n\n    if flag == 1:\n        res = cur.execute(\"select * from csdn_article\")\n        cur.execute(\n            'insert into csdn_article values(\"%s\",\"%s\", \"%s\", \"%s\", \"%s\", \"%s\")' % (res + 1, update[0], update[1], update[2],update[3], 0 ))\n    elif flag == 2:\n        cur.execute(\"update csdn_article set article_read=\"+str(update[1])+\" where article_id = \"+str(update[0]))\n        cur.execute(\"update csdn_article set change_read=\" + str(update[3]) + \"  where article_id = \" + str(update[0]))\n    elif flag == 3:\n        res = cur.execute(\"select article_read from csdn_article where article_id=\"+str(update))\n        if res == 1:\n            res = cur.fetchmany(res)[0][0]\n        elif res == 0:\n            res = -1\n        return res\n    elif flag == 4:\n        res = cur.execute(\"select article_comment from csdn_article where article_id=\" + str(update))\n        if res == 1:\n            res = cur.fetchmany(res)[0][0]\n        return res\n    elif flag == 5:\n        cur.execute(\n            \"update csdn_article set article_comment=\" + str(update[1]) + \"  where article_id = \" + str(update[0]))\n        # sql_list = list(cur.fetchmany(res))\n        # print sql_list[1].count(435)\n        # if 435 in sql_list:\n        #     print '432432443242'\n    cur.close()\n    conn.commit()\n    conn.close()\ndef main():\n    starttime = datetime.datetime.now()\n    article_all_list = []\n    text = ''\n    comment_num = 0\n    read_num = 0\n    for i in range(1, 10000):\n        url = 'http:\/\/blog.csdn.net\/rain_web\/svc\/getarticles?pageindex=' + str(i) + '&amp;pagesize=1&amp;categoryId=0&amp;'\n        html = DownLoad_Html(url)\n        if html == '':\n            break\n        title = re.findall('_blank\"&gt;(.*?)&lt;', html)\n        read = re.findall('span&gt;(.*?)&lt;', html)\n        id = re.findall('details\/(.*?)\"', html)\n        article_title = title[0]\n        article_read = int(read[0])\n        article_comment = int(read[1])\n        article_id = id[0]\n        # \u7136\u540e\u5c06\u6bcf\u4e00\u7bc7\u6587\u7ae0\u91cc\u7684\u6570\u636e\u653e\u5165\u4e00\u4e2a\u5217\u8868\u91cc\uff0c\u518d\u5c06\u8fd9\u4e2a\u5217\u8868\u653e\u5230\u5927\u7684\u5217\u8868\u91cc\n        article_list = []\n        article_list.append(article_id)\n        article_list.append(article_read)\n        article_list.append(article_title)\n        article_list.append(article_comment)\n        # \u7528\u4e8e\u5224\u65ad\u6709\u6ca1\u6709\u9605\u8bfb\u6b21\u6570\u7684\u6539\u53d8\uff0c\u5982\u679c\u6ca1\u6709\uff0c\u5219\u5728\u8bc4\u8bba\u6b21\u6570\u524d\u52a0\u6807\u9898\n        flag = 0\n        # \u5bf9\u6bcf\u4e2a\u503c\u53bb\u6570\u636e\u5e93\u91cc\u67e5\u627e\uff0c\u5982\u679c\u5b58\u5728\u5c31\u8fdb\u884c\u6bd4\u8f83\uff0c\u4e0d\u76f8\u540c\u5219\u8bb0\u5f55\u4e0b\u6765\uff0c\u5e76\u53bb\u6570\u636e\u5e93\u4e2d\u4fee\u6539\uff0c\u5982\u679c\u4e0d\u5b58\u5728\uff0c\u5219\u63d2\u5165\u8fd9\u6761\u6570\u636e\n        read = operator_SQL(3, article_id)\n        # \u9605\u8bfb\u6b21\u6570 -1 \u4ee3\u8868\u6570\u636e\u4e0d\u5b58\u5728\uff0c\u63d2\u5165\u6570\u636e\n        if read == -1:\n            operator_SQL(1, article_list)\n        # \u5982\u679c\u6570\u636e\u5e93\u4e2d\u9605\u8bfb\u6b21\u6570\u548c\u722c\u53d6\u7684\u9605\u8bfb\u6b21\u6570\u4e0d\u540c\n        elif read != article_read:\n            # \u5c06\u9605\u8bfb\u6b21\u6570\u7684\u5dee\u503c\u8bb0\u5f55\u4e0b\u6765\n            article_list.append(article_read - read)\n            # print article_list[3]\n            # \u4fee\u6539\u9605\u8bfb\u6b21\u6570\n            operator_SQL(2, article_list)\n            # article_all_list.append(article_list)\n            text = text + '\u6587\u7ae0\uff1a' + article_title + '\uff1a\u603b\u9605\u8bfb\u6b21\u6570\u4e3a\uff1a' + str(article_read) + '\uff1b\u6bd4\u6628\u5929\u589e\u52a0\u4e86\uff1a' + str(\n                article_read - read) + '\u6b21\u3002' + '\\n'\n            read_num = read_num + 1\n            # break\n        comment = operator_SQL(4, article_id)\n        if comment != article_comment:\n            # \u4fee\u6539\u6b21\u6570\n            comment_list = []\n            comment_list.append(article_id)\n            comment_list.append(article_comment)\n            operator_SQL(5, comment_list)\n            comment_num = comment_num + 1\n            text = text + '\u6587\u7ae0\uff1a' + article_title + '\uff1a\u8bc4\u8bba\u6b21\u6570\u4e3a\uff1a' + str(article_comment) + \"\uff1b\u6bd4\u6628\u5929\u589e\u52a0\u4e86\uff1a\" + str(\n                article_comment - comment) + '\u6b21\u3002' + '\\n'\n    text = \"\u60a8\u4eca\u5929\u7684CSDN\u535a\u5ba2\u4fe1\u606f\u62a5\u544a\u5982\u4e0b\uff1a\" + '\\n\u4eca\u65e5\u6709' + str(read_num) + \\\n           '\u7bc7\u6587\u7ae0\u7684\u9605\u8bfb\u6570\u53d1\u751f\u4e86\u53d8\u5316\\n' + '\u4eca\u65e5\u6709' + str(comment_num) + '\u7bc7\u6587\u7ae0\u7684\u8bc4\u8bba\u6570\u53d1\u751f\u4e86\u53d8\u5316\\n' + text\n    endtime = datetime.datetime.now()\n    text = text + '\\n\u672c\u6b21\u722c\u866b\u8fd0\u884c\u65f6\u95f4\u4e3a\uff1a' + str((endtime - starttime).seconds) + '\u79d2'\n    print text\n    email(text, 'nylrain@163.com')\nif __name__=='__main__':\n    main()\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>CSDN\u4e2a\u4eba\u535a\u5ba2\u9605\u8bfb\u8bc4\u8bba\u4fe1\u606f\u7684\u722c\u53d6 \u7528\u6765\u722c\u53d6CSDN\u4e0a\u4e2a\u4eba\u535a\u5ba2\u7684\u4fe1\u606f\uff0c\u5305\u62ec\u9605\u8bfb\u6b21\u6570\uff0c\u8bc4\u8bba\u6570\u7b49\u7b49 \u56e0\u4e3aCSDN\u66f4\u2026 <span class=\"read-more\"><a href=\"http:\/\/rain1024.com\/index.php\/2017\/12\/20\/article109\/\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":908,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[15],"tags":[58,81],"class_list":["post-907","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","tag-python","tag-reptile"],"_links":{"self":[{"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/posts\/907","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/comments?post=907"}],"version-history":[{"count":1,"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/posts\/907\/revisions"}],"predecessor-version":[{"id":1424,"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/posts\/907\/revisions\/1424"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/media\/908"}],"wp:attachment":[{"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/media?parent=907"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/categories?post=907"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/tags?post=907"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}