{"id":7978,"date":"2024-06-28T17:01:01","date_gmt":"2024-06-28T09:01:01","guid":{"rendered":""},"modified":"2024-06-28T17:01:01","modified_gmt":"2024-06-28T09:01:01","slug":"\u83b7\u53d6\u6307\u5b9a\u5143\u7d20\u7684\u4f4d\u7f6e_\u62fe\u53d6\u5750\u6807\u5730\u5740\u5750\u6807","status":"publish","type":"post","link":"https:\/\/mushiming.com\/7978.html","title":{"rendered":"\u83b7\u53d6\u6307\u5b9a\u5143\u7d20\u7684\u4f4d\u7f6e_\u62fe\u53d6\u5750\u6807\u5730\u5740\u5750\u6807"},"content":{"rendered":"

1.tag_name\u6807\u7b7e\u5b9a\u4f4d\uff1a\u76f8\u540c\u6807\u7b7e\u65f6\uff0c\u9ed8\u8ba4\u83b7\u53d6\u7b2c\u4e00\u4e2a\u6807\u7b7e<\/p>\n

1.1.\u9ed8\u8ba4\u60c5\u51b5\u4e0btag_name\u5b9a\u4f4d\u7b2c\u4e00\u4e2a\u5143\u7d20<\/p>\n

#\u5bfc\u5305\nfrom time import sleep\n\nfrom selenium import webdriver\nfrom selenium.webdriver.common.by import By\n\n#\u83b7\u53d6 \u6d4f\u89c8\u5668\u9a71\u52a8\u5bf9\u8c61\ndriver = webdriver.Chrome()\n#\u6253\u5f00\u6ce8\u518c\u9875\u9762\nurl = r\"D:\\\u63d0\u5347\u81ea\u6211\\\u8bfe\u5916\u5b66\u4e60\u6587\u4ef6\\\u8f6f\u4ef6\u6d4b\u8bd5\\WEB\u81ea\u52a8\u5316\u6d4b\u8bd5\\web\u81ea\u52a8\u5316_day01_\u8bfe\u4ef6+\u7b14\u8bb0+\u8d44\u6599+\u4ee3\u7801\\web\u81ea\u52a8\u5316_day01_\u8bfe\u4ef6+\u7b14\u8bb0+\u8d44\u6599+\u4ee3\u7801\\02_\u5176\u4ed6\u8d44\u6599\\\u6ce8\u518cA.html\"\ndriver.get(url)\n#\u4f7f\u7528tag_name\u5b9a\u4f4d\u7528\u6237\u540d \u5e76 \u8f93\u5165admin\n#\u6ce8\u610f\uff1a\u9875\u9762\u4e2d\u5982\u679c\u5b58\u5728\u591a\u4e2a\u76f8\u540c\u7684\u6807\u7b7e\uff0c\u9ed8\u8ba4\u8fd4\u56de\u7b2c\u4e00\u4e2a\u6807\u7b7e\ndriver.find_element(By.TAG_NAME,\"input\").send_keys(\"admin\")\n#\u6682\u505c3\u79d2\nsleep(3)<\/code><\/pre>\n

\u7ed3\u679c\u622a\u56fe\uff1a<\/p>\n

\"\u83b7\u53d6\u6307\u5b9a\u5143\u7d20\u7684\u4f4d\u7f6e_\u62fe\u53d6\u5750\u6807\u5730\u5740\u5750\u6807<\/p>\n

2.\u83b7\u53d6\u5176\u4ed6\u5143\u7d20\u7684\u65b9\u6cd5<\/p>\n

 2.1\u5f53\u6709\u591a\u4e2a\u76f8\u540c\u6807\u7b7e\u65f6\uff0c\u4f7f\u7528<\/p>\n

driver.find_elements(By.TAG_NAME,\"input\")<\/code><\/pre>\n

      \u7ed3\u679c\u8fd4\u56de\u4e00\u4e2a\u5217\u8868\u3002<\/p>\n

\u5f97\u5230\u6240\u6709\u6807\u7b7e\u76f8\u540c\u7684\u5143\u7d20\uff0c\u53ef\u4ee5\u4f7f\u7528\u5217\u8868\u904d\u5386\u7684\u5f62\u5f0f\uff0c\u5bf9\u5177\u4f53\u7684\u5143\u7d20\u505a\u64cd\u4f5c\u3002<\/p>\n

PS<\/strong>\uff1a\u5f97\u5230\u7684\u5217\u8868\u8fdb\u884c\u904d\u5386\u65f6\uff0c\u53ef\u4ee5\u5229\u7528\u5176\u4ed6\u5b9a\u4f4d\u65b9\u6cd5\u8fdb\u884c\u5f97\u5230\u5217\u8868\u5143\u7d20\u3002<\/strong><\/span><\/p>\n

#\u83b7\u53d6\u5176\u4ed6\u76f8\u540c\u5143\u7d20\u65b9\u6cd5 tag_list = driver.find_elements(By.TAG_NAME,\"input\") for i in tag_list: print(i.get_attribute(\"id\").strip()) #\u83b7\u53d6\u5168\u90e8input\u7684id\u5c5e\u6027\u503c #\u5224\u65adid\u5c5e\u6027\u503c\u662f\u5426\u4e3a\u2018passwordA\u2019 if(i.get_attribute(\"id\") == 'passwordA'): i.send_keys(\"\") #\u4e5f\u53ef\u4ee5\u6309\u7167\u6240\u8981\u5b9a\u4f4d\u7684\u5143\u7d20\u7684\u7d22\u5f15\u8fdb\u884c\u8f93\u5165 tag_list[1].send_keys(\"\") #\u6309\u7167\u8f93\u51fa\u7684id\u5c5e\u6027\u7136\u540e\u770b\u5217\u8868\u6240\u5728 sleep(3)<\/code><\/pre>\n

\u7ed3\u679c\u622a\u56fe\uff1a<\/p>\n

\"\u83b7\u53d6\u6307\u5b9a\u5143\u7d20\u7684\u4f4d\u7f6e_\u62fe\u53d6\u5750\u6807\u5730\u5740\u5750\u6807<\/p>\n

\u5b8c\u6574\u4ee3\u7801\uff1a<\/p>\n

#\u5bfc\u5305\nfrom time import sleep\n\nfrom selenium import webdriver\nfrom selenium.webdriver.common.by import By\n\n#\u83b7\u53d6 \u6d4f\u89c8\u5668\u9a71\u52a8\u5bf9\u8c61\ndriver = webdriver.Chrome()\n#\u6253\u5f00\u6ce8\u518c\u9875\u9762\nurl = r\"D:\\\u63d0\u5347\u81ea\u6211\\\u8bfe\u5916\u5b66\u4e60\u6587\u4ef6\\\u8f6f\u4ef6\u6d4b\u8bd5\\WEB\u81ea\u52a8\u5316\u6d4b\u8bd5\\web\u81ea\u52a8\u5316_day01_\u8bfe\u4ef6+\u7b14\u8bb0+\u8d44\u6599+\u4ee3\u7801\\web\u81ea\u52a8\u5316_day01_\u8bfe\u4ef6+\u7b14\u8bb0+\u8d44\u6599+\u4ee3\u7801\\02_\u5176\u4ed6\u8d44\u6599\\\u6ce8\u518cA.html\"\ndriver.get(url)\n#\u4f7f\u7528tag_name\u5b9a\u4f4d\u7528\u6237\u540d \u5e76 \u8f93\u5165admin\n#\u6ce8\u610f\uff1a\u9875\u9762\u4e2d\u5982\u679c\u5b58\u5728\u591a\u4e2a\u76f8\u540c\u7684\u6807\u7b7e\uff0c\u9ed8\u8ba4\u8fd4\u56de\u7b2c\u4e00\u4e2a\u6807\u7b7e\ndriver.find_element(By.TAG_NAME,\"input\").send_keys(\"admin\")\n#\u6682\u505c3\u79d2\nsleep(3)\n\n#\u83b7\u53d6\u5176\u4ed6\u76f8\u540c\u5143\u7d20\u65b9\u6cd5\ntag_list = driver.find_elements(By.TAG_NAME,\"input\")\n\nfor i in tag_list:\n    print(i.get_attribute(\"id\").strip())        #\u83b7\u53d6\u5168\u90e8input\u7684id\u5c5e\u6027\u503c\n    #\u5224\u65adid\u5c5e\u6027\u503c\u662f\u5426\u4e3a\u2018userA\u2019\n    if(i.get_attribute(\"id\") == 'passwordA'):\n        i.send_keys(\"123456\")\n\n#\u4e5f\u53ef\u4ee5\u6309\u7167\u6240\u8981\u5b9a\u4f4d\u7684\u5143\u7d20\u7684\u7d22\u5f15\u8fdb\u884c\u8f93\u5165\ntag_list[1].send_keys(\"123456\") #\u6309\u7167\u8f93\u51fa\u7684id\u5c5e\u6027\u7136\u540e\u770b\u5217\u8868\u6240\u5728\n\nsleep(3)\n#\u5173\u95ed\u9a71\u52a8\ndriver.quit()\n<\/code><\/pre>\n

  PS\uff1a\u5728web\u81ea\u52a8\u5316\u6d4b\u8bd5\u4e2d\u4f7f\u7528XPath\u5b9a\u4f4d\u548cCSS\u5c45\u591a\uff0c\u975e\u7279\u6b8a\u60c5\u51b5\u4e0b\u4e0d\u5efa\u8bae\u4f7f\u7528tag-name<\/p>\n","protected":false},"excerpt":{"rendered":"\u83b7\u53d6\u6307\u5b9a\u5143\u7d20\u7684\u4f4d\u7f6e_\u62fe\u53d6\u5750\u6807\u5730\u5740\u5750\u6807\u5f97\u5230\u6240\u6709\u6807\u7b7e\u76f8\u540c\u7684\u5143\u7d20\uff0c\u53ef\u4ee5\u4f7f\u7528\u5217\u8868\u904d\u5386\u7684\u5f62\u5f0f\uff0c\u5bf9\u5177\u4f53\u7684\u5143\u7d20\u505a\u64cd\u4f5c","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"_links":{"self":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/7978"}],"collection":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/comments?post=7978"}],"version-history":[{"count":0,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/7978\/revisions"}],"wp:attachment":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/media?parent=7978"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/categories?post=7978"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/tags?post=7978"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}