\u5229\u7528cookies\u767b\u5f55\u7f51\u7ad9<\/strong><\/span><\/div>\n\u5148\u6253\u5f00\u8981\u767b\u5f55\u7684\u7f51\u7ad9\uff0c\u7136\u540e\u5c06cookies\u4ece\u4e4b\u524d\u4fdd\u5b58\u7684json\u6587\u4ef6\u8bfb\u53d6\u51fa\u6765\uff0c\u7136\u540e\u6dfb\u52a0\u5230\u6d4f\u89c8\u5668\uff0c\u5237\u65b0\u754c\u9762\uff0c\u5373\u53ef\u5b9e\u73b0\u767b\u5f55\uff0c\u7136\u540e\u4fbf\u53ef\u4ee5\u8fdb\u884c\u53d1\u5fae\u535a\u7684\u64cd\u4f5c\uff0c\u5177\u4f53\u5143\u7d20\u5b9a\u4f4d\uff0c\u8bf7\u5927\u5bb6\u767e\u5ea6selenium\u7684\u4e00\u4e9b\u57fa\u672c\u7528\u6cd5\uff0c\u6b64\u5904\u4e0d\u518d\u8d58\u8ff0\u3002\u4ee3\u7801\u4e2d\u4e5f\u7ed9\u51fa\u4e86\u4e0d\u6253\u5f00\u6d4f\u89c8\u5668\u7684\u65b9\u5f0f\u6765\u5b9e\u73b0\u529f\u80fd\u3002<\/p>\n
\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n
\r\n #!\/usr\/bin\/python\r\n #coding=utf-8\r\n \r\n from selenium import webdriver\r\n import json\r\n import time\r\n \r\n file = 'cookies.json'\r\n #\u6253\u5f00\u6d4f\u89c8\u5668\uff0c\u82e5\u4e0d\u60f3\u6253\u5f00\u6d4f\u89c8\u5668\u8fd0\u884c\u811a\u672c\uff0c\u53ef\u4ee5\u4f7f\u7528\u4e0b\u9762\u6ce8\u91ca\u6389\u7684\u65b9\u6cd5\r\n driver = webdriver.Firefox()\r\n \r\n #\u4ee5headless\u6a21\u5f0f\u8fd0\u884c\u811a\u672c\uff0c\u53ef\u4ee5\u5b9e\u73b0\u4e0d\u6253\u5f00\u6d4f\u89c8\u5668\u5bf9\u7f51\u7ad9\u8fdb\u884c\u64cd\u4f5c\r\n #option = webdriver.FirefoxOptions()\r\n #option.add_argument(argument='-headless')\r\n #driver = webdriver.Firefox(firefox_options=option)\r\n \r\n #\u6253\u5f00\u7f51\u5740\r\n def open_url(url):\r\n driver.get(url)\r\n driver.implicitly_wait(5)\r\n driver.maximize_window()\r\n \r\n #\u5411\u6d4f\u89c8\u5668\u6dfb\u52a0\u4fdd\u5b58\u7684cookies\r\n def add_cookies():\r\n fp = open(file,'r')\r\n cookies = json.load(fp)\r\n fp.close()\r\n for cookie in cookies:\r\n driver.add_cookie(cookie) \r\n \r\n if __name__ == \"__main__\":\r\n #\u8f93\u5165\u8981\u6253\u5f00\u7684\u7f51\u7ad9\u5e76\u6253\u5f00\r\n test_url = raw_input('please input url:')\r\n open_url(test_url)\r\n time.sleep(5)\r\n #\u6dfb\u52a0cookies\u540e\u5237\u65b0\u754c\u9762\uff0c\u5b9e\u73b0\u514d\u5bc6\u767b\u5f55\r\n add_cookies()\r\n driver.refresh()\r\n # \u53d1\u9001\u5fae\u535a\r\n #\u5b9a\u4f4d\u5230\u5fae\u535a\u8f93\u5165\u6846\uff0c\u70b9\u51fb\u8f93\u5165\u6846\r\n driver.find_element_by_xpath(\"\/\/textarea[@class='W_input']\").click()\r\n time.sleep(2)\r\n #\u8f93\u5165\u9700\u8981\u53d1\u9001\u7684\u5185\u5bb9\r\n driver.find_element_by_xpath(\"\/\/textarea[@class='W_input']\").send_keys('Test message')\r\n time.sleep(3)\r\n #\u70b9\u51fb\u53d1\u9001\u6309\u94ae\r\n driver.find_element\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"\u83b7\u53d6\u7684cookies\u4f1a\u4fdd\u5b58\u4e3a\u4e00\u4e2ajson\u683c\u5f0f\u7684\u6587\u4ef6\u3002\u4e0d\u8fc7\u5728\u6253\u5f00\u7f51\u7ad9\u540e\uff0c\u767b\u5f55\u64cd\u4f5c\u9700\u8981\u81ea\u5df1\u624b\u52a8\u8fdb\u884c\u4e00\u4e0b\uff0c\u4ee3\u7801\u4e2d\u6709\u6ce8 […]<\/p>\n","protected":false},"author":1479,"featured_media":153246,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-153245","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/153245","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1479"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=153245"}],"version-history":[{"count":3,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/153245\/revisions"}],"predecessor-version":[{"id":153351,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/153245\/revisions\/153351"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/153246"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=153245"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=153245"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=153245"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}