{"id":192001,"date":"2010-12-08T06:25:26","date_gmt":"2010-12-07T22:25:26","guid":{"rendered":"\/?p=192001"},"modified":"2014-03-14T02:40:35","modified_gmt":"2014-03-13T18:40:35","slug":"%e9%99%84%e8%b5%a0%e4%ba%ba%e4%ba%ba%e5%a5%bd%e5%8f%8b%e4%b8%bb%e9%a1%b5%e7%88%ac%e8%99%ab%e8%84%9a%e6%9c%ac%e4%bb%a3%e7%a0%81","status":"publish","type":"post","link":"https:\/\/yangzhe1991.org\/blog\/2010\/12\/%e9%99%84%e8%b5%a0%e4%ba%ba%e4%ba%ba%e5%a5%bd%e5%8f%8b%e4%b8%bb%e9%a1%b5%e7%88%ac%e8%99%ab%e8%84%9a%e6%9c%ac%e4%bb%a3%e7%a0%81\/","title":{"rendered":"\u9644\u8d60\u4eba\u4eba\u597d\u53cb\u4e3b\u9875\u722c\u866b\u811a\u672c\u4ee3\u7801"},"content":{"rendered":"<p><span style=\"font-size: medium;\">\u4f9d\u7136\u58f0\u660e\uff1a\u5199\u7684\u5f88\u70c2<\/span><\/p>\n<p><span style=\"font-size: medium;\">\u4e0d\u6253\u5305\u4e86\uff0c\u76f4\u63a5\u653e\u4ee3\u7801\u4e86<\/span><\/p>\n<p><!--more--><\/p>\n<pre class=\"brush: python;fontsize: 100; first-line: 1; \">import urllib\nimport urllib2\nimport cookielib\nimport sys\nfrom StringIO import StringIO\ndef login(s):\n\txn={}\n\txn['email']='asd'\n\txn['password']='213'\n\tcookie=cookielib.CookieJar()\n\topener=urllib2.build_opener(urllib2.HTTPCookieProcessor(cookie))\n\turllib2.install_opener(opener)\n\tzhanghao = urllib.urlencode(xn)\n\treq=urllib2.Request('http:\/\/3g.renren.com\/login.do?fx=0&amp;autoLogin=true',zhanghao)\n\tresp=urllib2.urlopen(req)\n\thtml=urllib2.urlopen(s)\n\treturn html.read()<\/pre>\n<pre class=\"brush: python;fontsize: 100; first-line: 1; \"># coding=utf-8\nimport urllib\nimport urllib2\nimport cookielib\nimport sys\nfrom time import sleep\nfrom login import *\n\nhtml=login('http:\/\/3g.renren.com\/myfriendlist.do')\nhtml=html[html.find('\u5168\u90e8'):]\nlast='123'\ntotal=0\nn=0\ni=0\nwhile html.find('\u4e0b\u4e00\u9875')&gt;=0:\n\thtml=html[html.find('\u5168\u90e8'):html.find('\u4e0b\u4e00\u9875')]\n\twhile html.find('profile.do?h')&gt;=0:\n\t\thtml=html[html.find('&lt;a href'):]\n\t\thtml=html[html.find('\" '):]\n\t\thtml=html[html.find('&lt;a href'):]\n\t\ttemp=html[html.find('\"')+1:html.find('\"&gt;')]\n\t\tpro=login(temp)\n\t\tsleep(2)\n\t\tname=pro[pro.find('\u7f51')+6:pro.find('&lt;\/title')]\n\t\tpro=pro[pro.find('&gt;\u5206\u4eab&lt;'):]\n\t\tnum=pro[pro.find('&gt;(')+2:pro.find(')&lt;')]\n\t\tnum=int(num)\n\t\tn=n+1\n\t\tprint name,num\n\t\tf=open('fenxiang.txt','a')\n\t\tf.write(name+' '+str(num)+'n')\n\t\tf.close()\n\t\ttotal+=num\n\t\thtml=html[html.find('\" '):]\n\ti+=1\n\thtml=login('http:\/\/3g.renren.com\/myfriendlist.do?curpage='+str(i))\n\nf=open('fenxiang.txt','a')\nf.write('total:'+str(total)+'nnum:'+str(n)+'naverage:'+str(total\/\/n)+'n')\nf.close()<\/pre>\n<p>&nbsp;<\/p>\n<pre class=\"brush: python;fontsize: 100; first-line: 1; \"># coding=utf-8\ndic={}\nf=open('fenxiang.txt','r')\nfor eachline in f:\n\tdic[eachline[:eachline.find(' ')]]=int(eachline[eachline.find(' ')+1:eachline.find('n')])\nf2=open('fenxiangsort.txt','w')\ndic2= (sorted(dic.iteritems(), key=lambda d:d[1], reverse = True ))\nfor i in dic2:\n\tf2.write(i[0]+' '+str(i[1])+'n')<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>\u8bf4\u660e\uff1a\u7b2c\u4e00\u4e2alogin.py\u5c31\u662f\u6839\u636e\u4ee5\u524d\u90a3\u4e2a\u673a\u5668\u4eba\u7684\u4ee3\u7801\u6539\u7684\uff0c\u53ea\u4e0d\u8fc7\u51fd\u6570\u4f1a\u8fd4\u56de\u53c2\u6570\u7684\u5730\u5740\u7684HTML\u5b57\u7b26\u4e32<\/p>\n<p>\u7b2c\u4e8c\u4e2a\u5c31\u662f\u4e3b\u7a0b\u5e8f\u4e86\uff0c\u91cc\u9762\u76f8\u5e94\u505a\u4fee\u6539\u53ef\u4ee5\u67e5\u522b\u7684<\/p>\n<p>\u7b2c\u4e09\u4e2a\u662f\u6392\u5e8f\u7528\u7684\uff0c\u8bb2\u4eba\u540d\u8ddf\u6570\u91cf\u5f04\u6210\u5b57\u5178\u6309value\u6392\u5e8f\uff0c\u65b9\u6cd5\u662f\u7f51\u4e0a\u641c\u7684\u3002\u4e0d\u8fc7\u6709\u4e2a\u95ee\u9898\u662f\u6709\u4eba\u540d\u5b57\u4e4b\u95f4\u6709\u7a7a\u683c\uff08\u4e3b\u8981\u662f\u82f1\u6587\u540d\u4ec0\u4e48\u7684\uff09\uff0c\u6570\u91cf\u4e0d\u591a\u6211\u624b\u52a8\u53bb\u6389\u7684&hellip;&hellip;<\/p>\n<p>import\u6709\u51e0\u4e2a\u662f\u6ca1\u7528\u7684<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4f9d\u7136\u58f0\u660e\uff1a\u5199\u7684\u5f88\u70c2 \u4e0d\u6253\u5305\u4e86\uff0c\u76f4\u63a5\u653e\u4ee3\u7801\u4e86<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[18],"_links":{"self":[{"href":"https:\/\/yangzhe1991.org\/blog\/wp-json\/wp\/v2\/posts\/192001"}],"collection":[{"href":"https:\/\/yangzhe1991.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/yangzhe1991.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/yangzhe1991.org\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/yangzhe1991.org\/blog\/wp-json\/wp\/v2\/comments?post=192001"}],"version-history":[{"count":1,"href":"https:\/\/yangzhe1991.org\/blog\/wp-json\/wp\/v2\/posts\/192001\/revisions"}],"predecessor-version":[{"id":224541,"href":"https:\/\/yangzhe1991.org\/blog\/wp-json\/wp\/v2\/posts\/192001\/revisions\/224541"}],"wp:attachment":[{"href":"https:\/\/yangzhe1991.org\/blog\/wp-json\/wp\/v2\/media?parent=192001"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/yangzhe1991.org\/blog\/wp-json\/wp\/v2\/categories?post=192001"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/yangzhe1991.org\/blog\/wp-json\/wp\/v2\/tags?post=192001"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}