{"id":332,"date":"2017-10-20T18:11:01","date_gmt":"2017-10-20T10:11:01","guid":{"rendered":"http:\/\/120.76.142.240\/?p=332"},"modified":"2017-10-20T18:11:01","modified_gmt":"2017-10-20T10:11:01","slug":"python%e7%88%ac%e8%99%ab","status":"publish","type":"post","link":"http:\/\/ssynas.top\/?p=332","title":{"rendered":"python\u722c\u866b"},"content":{"rendered":"<p><a href=\"http:\/\/120.76.142.240\/2018\/04\/15\/\u901a\u7528\u6f0f\u6d1e\u722c\u866b\/\">\u8fd9\u6709\u4e00\u4e2a\u65b0\u7684\u4f8b\u5b50<\/a><\/p>\n<p>\u672c\u6587\u53ef\u4ee5\u65e0\u89c6\u6389\u4e86\uff0c\u76f4\u63a5\u770b\u4e0a\u9762\u7684\u94fe\u63a5\u5427\uff0c\u5220\u8d77\u6765\u6709\u70b9\u9ebb\u70e6\u5148\u653e\u5728\u8fd9<\/p>\n<h1><strong>\u9759\u6001\u7f51\u9875\u7684\u6293\u53d6<\/strong><\/h1>\n<p>\u4e00\u5f00\u59cb\u7528urlbin\uff0c\u4f46\u662f\u8fd9\u4e2a\u53ea\u80fd\u6293\u9759\u6001\u7f51\u9875\uff0c\u73b0\u5728\u6ca1\u6709\u51e0\u4e2a\u7f51\u9875\u662f\u9759\u6001\u7684\u4e86\uff0c\u90fd\u662f\u7528\u7684ajax\u52a8\u6001\u52a0\u8f7d\u3002\u8fd9\u4e2a\u5982\u679c\u6293\u53d6\u52a8\u6001\u7f51\u9875\uff0c\u7f51\u9875\u4f1a\u4e0d\u5168<\/p>\n<p>\u9644\u4e0a\u6e90\u7801<\/p>\n<p>#-*-coding:utf-8-*-<br \/>\n#\u722c\u53d6\u56fe\u7247<br \/>\n#\u6253\u5f00\u7684\u7f51\u9875\u4e0d\u5168\uff0c\u56e0\u4e3a\u7f51\u9875\u6709\u52a8\u6001\u52a0\u8f7d\u3002\u4e8e\u662f\u53c8\u5199\u4e86\u4e2a\u57fa\u4e8eselenium\u7684\u722c\u866b\uff0c\u5b8c\u5168\u6a21\u62df\u6d4f\u89c8\u5668\u884c\u4e3a<br \/>\n#urllib\u4e5f\u7b97\u662f\u5904\u7406\u9759\u6001\u7f51\u9875\u6700\u5bb9\u6613\u4e0a\u624b\u7684\u5e93\u4e86\uff0c\u7b80\u5355\u7684\u722c\u866b\u7528\u8fd9\u4e2a\u6700\u597d\u5199<\/p>\n<p>import re<br \/>\nimport urllib2<br \/>\nimport urllib<br \/>\nimport pyquery<\/p>\n<p>#http\u5934\uff0c\u6ca1\u5565\u610f\u4e49<br \/>\nheader = {<br \/>\n&#8216;User-Agent&#8217;:&#8217;Mozilla\/5.0\u00a0(Windows;\u00a0U;\u00a0Windows\u00a0NT\u00a06.1;\u00a0en-US;\u00a0rv:1.9.1.6)\u00a0Gecko\/20091201\u00a0Firefox\/3.5.6&#8242;<br \/>\n&#8216;Connection: Keep-Alive&#8217;<br \/>\n&#8216;Referer: http:\/\/www.baidu.com&#8217;<br \/>\n&#8216;Pragma: no-cache&#8217;<br \/>\n&#8216;Accept: application\/json, text\/javascript, *\/*; q=0.01&#8242;<br \/>\n}<\/p>\n<p>#\u8bfb\u53d6\u7f51\u9875<br \/>\ndef openURL(url):<br \/>\na = urllib2.Request(url = url,headers = header)<br \/>\ndomin = urllib2.urlopen(a)<br \/>\ncontent = domin.read()<br \/>\nreturn content<\/p>\n<p>#\u8fd9\u4e2a\u6b63\u5219\u53ef\u80fd\u4e5f\u6709\u95ee\u9898\uff0c\u4f46\u662f\u4e00\u5f00\u59cb\u4e0d\u5168\u786e\u5b9e\u662f\u7f51\u9875\u4ee3\u7801\u662f\u52a8\u6001\u52a0\u8f7d\uff0cURLBIL\u6ca1\u52a0\u8f7d\u7684\u5173\u7cfb<br \/>\ndef comp(str):<br \/>\nrere = r&#8217;src=&#8221;(.*?\\.jpg)&#8221; bdwater=&#8217;<br \/>\ncompicture = re.compile(rere)<br \/>\npictures = re.findall(compicture,str)<br \/>\nreturn pictures<\/p>\n<p>def main():<br \/>\nindex = 0<br \/>\nwanna = comp(openURL(&#8216;http:\/\/tieba.baidu.com\/p\/2166231880&#8242;))<br \/>\nfor i in wanna:<br \/>\nindex = index + 1<br \/>\nurllib.urlretrieve(i,&#8217;pic\/%d.jpg&#8217; % index)<br \/>\nprint &#8220;[+] Saved &#8220;+ str(index) + &#8220;.jpg&#8221;<\/p>\n<p>if __name__ == &#8216;__main__&#8217;:<br \/>\nmain()<\/p>\n<p>&nbsp;<\/p>\n<h1>\u52a8\u6001\u7f51\u9875\u7684\u6293\u53d6<\/h1>\n<h6>\u7136\u540e\u5199\u4e86\u4e2a\u7b2c\u4e8c\u4e2a\u7248\u672c\uff0c\u7528selenium\u6a21\u62df\u6d4f\u89c8\u5668\u7684\u6574\u4e2a\u8bbf\u95ee\u8fc7\u7a0b\uff0c\u8fd9\u4e2a\u4e1c\u897f\u4f1a\u7b49\u5230\u7f51\u9875\u52a0\u8f7d\u6e32\u67d3\u5b8c\u4e4b\u540e\u624d\u4f1a\u8fdb\u884c\u4e4b\u540e\u7684\u4ee3\u7801<\/h6>\n<p>#-*-coding:utf-8-*-<br \/>\n#\u5b8c\u5168\u6a21\u4eff\u6d4f\u89c8\u5668\u884c\u4e3a,\u5229\u7528\u7b2c\u56db\u884c\u7684\u5e93\u53ef\u4ee5\u6253\u5f00\u4e00\u4e2a\u6d4f\u89c8\u5668\uff0c\u6a21\u62df\u6d4f\u89c8\u5668\u64cd\u4f5c<\/p>\n<p>from selenium import webdriver<br \/>\nimport urllib<br \/>\nimport re<\/p>\n<p>#\u4e00\u5f00\u59cb\u5b58\u7f51\u9875\u6e90\u4ee3\u7801\u7684\u65f6\u5019\u7f16\u7801\u6709\u95ee\u9898\uff0c\u4ee5\u524d\u6709\u8fc7\u7c7b\u4f3c\u7684\u7684\u60c5\u51b5<br \/>\nimport sys<br \/>\nreload(sys)<br \/>\nsys.setdefaultencoding(&#8216;utf-8&#8217;)<\/p>\n<p>#\u6a21\u62df\u6d4f\u89c8\u5668\u64cd\u4f5c\uff0c\u8fd9\u4e5f\u7b97\u662f\u5904\u7406\u52a8\u6001\u7f51\u9875\u901a\u7528\u7684\u65b9\u6cd5<br \/>\ndef getwholesource(url):<br \/>\nchrome = webdriver.Chrome()<br \/>\nchrome.get(&#8216;http:\/\/tieba.baidu.com\/p\/2166231880&#8242;)<br \/>\n#\u7528js\u628a\u7f51\u9875\u62c9\u5230\u6700\u4e0b\u9762\uff0c\u4e3b\u8981\u76ee\u7684\u662f\u89e6\u53d1JS\u4e8b\u4ef6\u4f7fAjax\u52a0\u8f7d\u5185\u5bb9\uff08\u524d\u4e24\u5929\u770bXSS\u7684\u65f6\u5019\u5b66\u4e86\u4e00\u70b9JS<br \/>\njs = &#8220;var q=document.documentElement.scrollTop=40000&#8221;<br \/>\nchrome.execute_script(js)<br \/>\nstr1 = chrome.page_source<br \/>\nreturn str1<\/p>\n<p>#\u6b63\u5219\u5339\u914d\uff0c\u627e\u51fa\u56fe\u7247\u7684URL<br \/>\ndef comp(str1):<br \/>\n#\u53d1\u73b0\u6240\u6709\u56fe\u7247\u7684URL\u7684\u957f\u5ea6\u662f\u4e00\u6837\u7684\uff0c\u8fd9\u4e2a\u6b63\u5219\u6709\u70b9\u5077\u61d2\u4e86\uff0c\u4f46\u786e\u5b9e\u6709\u7528<br \/>\nrere = r&#8217;http:\/\/.{182}\\.jpg&#8217;<br \/>\ncompicture = re.compile(rere)<br \/>\npictures = re.findall(compicture,str1)<br \/>\nreturn pictures<\/p>\n<p>#\u6700\u540e\u5229\u7528urlbin.urlretrieve\u65b9\u6cd5\u4e0b\u8f7d\u56fe\u7247<br \/>\ndef main():<br \/>\npic = comp(getwholesource(&#8216;http:\/\/tieba.baidu.com\/p\/2166231880&#8217;))<br \/>\nindex = 0<br \/>\nfor i in pic:<br \/>\nindex = index + 1<br \/>\nurllib.urlretrieve(i, &#8216;pic\/%d.jpg&#8217; % index)<br \/>\nprint &#8220;[+] Saved &#8221; + str(index) + &#8220;.jpg&#8221;<\/p>\n<p>if __name__ == &#8216;__main__&#8217;:<br \/>\nmain()<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8fd9\u6709\u4e00\u4e2a\u65b0\u7684\u4f8b\u5b50 \u672c\u6587\u53ef\u4ee5\u65e0\u89c6\u6389\u4e86\uff0c\u76f4\u63a5\u770b\u4e0a\u9762\u7684\u94fe\u63a5\u5427\uff0c\u5220\u8d77\u6765\u6709\u70b9&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-332","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"http:\/\/ssynas.top\/index.php?rest_route=\/wp\/v2\/posts\/332","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/ssynas.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/ssynas.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/ssynas.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/ssynas.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=332"}],"version-history":[{"count":0,"href":"http:\/\/ssynas.top\/index.php?rest_route=\/wp\/v2\/posts\/332\/revisions"}],"wp:attachment":[{"href":"http:\/\/ssynas.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=332"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/ssynas.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=332"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/ssynas.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=332"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}