{"id":758,"date":"2023-02-26T16:09:22","date_gmt":"2023-02-26T08:09:22","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=758"},"modified":"2023-04-29T17:00:16","modified_gmt":"2023-04-29T09:00:16","slug":"python-selenium-locate-a-set-of-elements","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/02\/26\/python-selenium-locate-a-set-of-elements\/","title":{"rendered":"Python Selenium\u5b9a\u4f4d\u4e00\u7ec4\u5143\u7d20"},"content":{"rendered":"<p>WebDriver\u8fd8\u63d0\u4f9b\u4e868\u79cd\u7528\u4e8e\u5b9a\u4f4d\u4e00\u7ec4\u5143\u7d20\u7684\u65b9\u6cd5\u3002<\/p>\n<ul>\n<li>find_elements_by_id()<\/li>\n<li>find_elements_by_name()<\/li>\n<li>find_elements_by_class_name()<\/li>\n<li>find_elements_by_tag_name()<\/li>\n<li>find_elements_by_link_text()<\/li>\n<li>find_elements_by_partial_link_text()<\/li>\n<li>find_elements_by_xpath()<\/li>\n<li>find_elements_by_css_selector()<\/li>\n<\/ul>\n<p><!-- more --><\/p>\n<p>\u5b9a\u4f4d\u4e00\u7ec4\u5143\u7d20\u7684\u65b9\u6cd5\u4e0e\u5b9a\u4f4d\u5355\u4e2a\u5143\u7d20\u7684\u65b9\u6cd5\u7c7b\u4f3c\uff0c\u552f\u4e00\u7684\u533a\u522b\u662f\u5728\u5355\u8bcdelement\u540e\u9762\u591a\u4e86\u4e00\u4e2as\u8868\u793a\u590d\u6570\u3002<\/p>\n<p>\u63a5\u4e0b\u6765\u901a\u8fc7\u4f8b\u5b50\u6f14\u793a\u5b9a\u4f4d\u4e00\u7ec4\u5143\u7d20\u7684\u4f7f\u7528\uff1a<\/p>\n<pre><code class=\"language-python\">from selenium import webdriver\nfrom time import sleep\n\ndriver = webdriver.Chrome()\ndriver.get(&quot;https:\/\/www.baidu.com&quot;)\n\ndriver.find_element_by_id(&quot;kw&quot;).send_keys(&quot;AppBlog.CN&quot;)\ndriver.find_element_by_id(&quot;su&quot;).click()\nsleep(1)\n\n# \u5b9a\u4f4d\u4e00\u7ec4\u5143\u7d20\ntexts = driver.find_elements_by_xpath(&#039;\/\/div\/h3\/a&#039;)\n\n# \u5faa\u73af\u904d\u5386\u51fa\u6bcf\u4e00\u6761\u641c\u7d22\u7ed3\u679c\u7684\u6807\u9898\nfor t in texts:\n    print(t.text)\n\ndriver.quit()<\/code><\/pre>\n<p>\u7a0b\u5e8f\u8fd0\u884c\u7ed3\u679c\uff1a<\/p>\n<pre><code>APP\u5f00\u53d1\u6280\u672f\u535a\u5ba2\n\u5e94\u7528\u4e2d\u5fc3-Z-BlogPHP &amp; Z-Blog 2\u540e\u53f0\u8d44\u6e90\u5927\u672c\u8425,\u63d0\u4f9bZ-BlogPHP &amp; Z...\nSina App Engine Blog | \u65e0\u5904\u4e0d\u5728 \u89e6\u624b\u53ef\u53ca\n\u535a\u5ba2\u56ed - \u5f00\u53d1\u8005\u7684\u7f51\u4e0a\u5bb6\u56ed\n\u65b0\u6d6a\u535a\u5ba2\u9996\u9875_\u65b0\u6d6a\u7f51\nBLOG APP \u63a8\u5e7f\u9875\nXamarin Android \u6253\u9020\u5c5e\u4e8e\u81ea\u5df1\u7684\u535a\u5ba2\u56edAPP(4) - IT\u80e1\u5c0f\u5e05 - \u535a\u5ba2\u56ed\nwhatsapp blog - WhatsApp \u535a\u5ba2\napp\u7aef\u7ef4\u6301\u7528\u6237\u767b\u5f55\u72b6\u6001 - CSDN\u535a\u5ba2\n\u65b0\u6d6a\u535a\u5ba2\u9996\u9875_\u65b0\u6d6a\u7f51\napp \u3010\u732a\u516b\u6212\u7f51APP\u5f00\u53d1\u3011\u4e13\u4e1a\u5e73\u53f0 \u6ee1\u610f\u4ed8\u6b3e<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>WebDriver\u8fd8\u63d0\u4f9b\u4e868\u79cd\u7528\u4e8e\u5b9a\u4f4d\u4e00\u7ec4\u5143\u7d20\u7684\u65b9\u6cd5\u3002 find_elements_by_id() find_ [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[221],"tags":[],"class_list":["post-758","post","type-post","status-publish","format-standard","hentry","category-selenium"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/758","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=758"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/758\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=758"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=758"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=758"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}