{"id":1111,"date":"2018-07-31T11:14:30","date_gmt":"2018-07-31T03:14:30","guid":{"rendered":"http:\/\/www.sniper97.cn\/?p=1111"},"modified":"2018-07-31T11:14:30","modified_gmt":"2018-07-31T03:14:30","slug":"%e7%ac%ac%e5%8d%81%e4%ba%94%e8%8a%82%ef%bc%9a%e6%a8%a1%e6%8b%9f%e7%99%bb%e9%99%86","status":"publish","type":"post","link":"http:\/\/www.sniper97.cn\/index.php\/note\/carwler\/1111\/","title":{"rendered":"\u7b2c\u5341\u4e94\u8282\uff1a\u6a21\u62df\u767b\u9646"},"content":{"rendered":"<p>\u672c\u9875\u4ee3\u7801\u53ef\u4ee5\u5728<a href=\"https:\/\/github.com\/Sniper970119\/Spider\/tree\/master\/20180721\" target=\"_blank\" rel=\"noopener\" data-slimstat=\"5\">\u8fd9\u91cc<\/a>\u4e0b\u8f7d\u3002<br \/>\n\u9996\u5148\u6a21\u62df\u767b\u5f55github\uff0c\u94fe\u63a5\u662f<a href=\"http:\/\/www.github.com\/login\" target=\"_blank\" rel=\"noopener\">http:\/\/www.github.com\/login<\/a><br \/>\n\u9996\u5148\u89c2\u5bdf\u8bf7\u6c42\uff0c\u63d0\u4ea4\u4e00\u4e2afrom data \u5176\u4e2d\u5305\u62ec5\u4e2a\u53c2\u6570\uff0c\u5176\u4e2d\u7b2c\u4e09\u4e2a\u4e0d\u660e\u786e\u4ee3\u8868\u4ec0\u4e48\uff0c\u6240\u4ee5\u731c\u6d4b\u53ef\u80fd\u662f\u4e00\u4e2a\u52a0\u5bc6\u53c2\u6570\u3002<br \/>\n\u6211\u4eec\u6e05\u7a7acookies\u518d\u8bbf\u95ee\u754c\u9762\uff0c\u4f1a\u53d1\u73b0\u6e90\u7801\u4e2d\u53ef\u4ee5\u627e\u5230\u8be5\u53c2\u6570\uff0c\u6240\u4ee5\u6211\u4eec\u53ef\u4ee5\u83b7\u53d6\u8be5\u53c2\u6570\u7136\u540e\u6784\u6210\u8868\u5355\u6570\u636e\u3002<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.sniper97.cn\/wp-content\/uploads\/2018\/07\/95.png\" alt=\"\" class=\"alignnone size-full wp-image-1113\" width=\"878\" height=\"537\" \/><br \/>\n\u6211\u4eec\u9996\u5148\u53ef\u4ee5\u53d1\u73b0\uff0c\u8fd4\u56de\u7684\u6e90\u7801\u662f\u767b\u5f55\u4e4b\u540e\u7684\u754c\u9762\uff0c\u53ef\u4ee5\u770b\u5230\u7528\u6237\u540d\u3002<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.sniper97.cn\/wp-content\/uploads\/2018\/07\/96.png\" alt=\"\" class=\"alignnone size-full wp-image-1114\" width=\"816\" height=\"385\" \/><br \/>\n\u8fd9\u91cc\u4f7f\u7528session\uff0c\u53ef\u4ee5\u4fdd\u5b58\u7684cookies\uff0c\u7136\u540e\u4f7f\u7528cookies\u8bbf\u95ee\u522b\u7684\u754c\u9762\uff0c\u6211\u4eec\u518d\u83b7\u53d6\u5230session\u540e\u8bbf\u95ee\u8d44\u6599\u4fee\u6539\u754c\u9762\u628a\u7528\u6237\u540d\u548c\u535a\u5ba2\u5730\u5740\u722c\u53d6\u4e0b\u6765\uff0c\u89c2\u5bdf\u7528\u6237\u540d\u548c\u535a\u5ba2\u5730\u5740\u5e76\u627e\u5230\u5bf9\u5e94\u7684XPath\u8bed\u53e5\u3002 <img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.sniper97.cn\/wp-content\/uploads\/2018\/07\/97.png\" alt=\"\" class=\"alignnone size-full wp-image-1115\" width=\"1015\" height=\"452\" \/> <img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.sniper97.cn\/wp-content\/uploads\/2018\/07\/98.png\" alt=\"\" class=\"alignnone size-full wp-image-1116\" width=\"950\" height=\"249\" \/><br \/>\n\u7a0b\u5e8f\u8f93\u51fa\u6210\u529f\uff1a<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.sniper97.cn\/wp-content\/uploads\/2018\/07\/99.png\" alt=\"\" class=\"alignnone size-full wp-image-1117\" width=\"281\" height=\"104\" \/><br \/>\n&nbsp;<br \/>\n\u6e90\u7801\uff1a<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\"># -*- coding:utf-8 -*-\nimport requests\nfrom lxml import etree\nclass Login():\n    def __init__(self):\n        self.headers = {\n            'referer': 'https:\/\/github.com\/',\n            'user-agent': 'Mozilla\/5.0 (Windows NT 10.0; WOW64) '\n                          'AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/57.0.2987.133 Safari\/537.36',\n            'Host': 'github.com'\n        }\n        self.login_url = 'https:\/\/github.com\/login'\n        self.post_url = 'https:\/\/github.com\/session'\n        self.logined_url = 'https:\/\/github.com\/settings\/profile'\n        self.session = requests.Session()\n    def token(self):\n        response = self.session.get(self.login_url, headers=self.headers)\n        selector = etree.HTML(response.text)\n        token = selector.xpath('\/\/div\/\/input[2]\/@value')\n        return token\n    def login(self, email, password):\n        post_data = {\n            'commit': 'Sign in',\n            'utf8': '\u2713',\n            'authenticity_token': self.token()[0],\n            'login': email,\n            'password': password\n        }\n        self.session.post(self.post_url, data=post_data, headers=self.headers)\n        response = self.session.get(self.logined_url, headers=self.headers)\n        if response.status_code == 200:\n            self.profile(response.text)\n    def profile(self, html):\n        selector = etree.HTML(html)\n        name = selector.xpath('\/\/*[@id=\"user_profile_name\"]\/@value')[0]\n        email = selector.xpath('\/\/*[@id=\"user_profile_blog\"]\/@value')[0]\n        print(name, '\\n', email)\nif __name__ == \"__main__\":\n    login = Login()\n    login.login(email='359366783@qq.com', password='000000')\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u672c\u9875\u4ee3\u7801\u53ef\u4ee5\u5728\u8fd9\u91cc\u4e0b\u8f7d\u3002 \u9996\u5148\u6a21\u62df\u767b\u5f55github\uff0c\u94fe\u63a5\u662fhttp:\/\/www.github.com [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_mi_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[12],"tags":[],"views":4956,"_links":{"self":[{"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/posts\/1111"}],"collection":[{"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/comments?post=1111"}],"version-history":[{"count":0,"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/posts\/1111\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/media?parent=1111"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/categories?post=1111"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/tags?post=1111"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}