{"id":756,"date":"2023-02-26T16:08:02","date_gmt":"2023-02-26T08:08:02","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=756"},"modified":"2023-04-29T17:00:38","modified_gmt":"2023-04-29T09:00:38","slug":"python-selenium-obtain-assertion-information","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/02\/26\/python-selenium-obtain-assertion-information\/","title":{"rendered":"Python Selenium\u83b7\u53d6\u65ad\u8a00\u4fe1\u606f"},"content":{"rendered":"<p>\u4e0d\u7ba1\u662f\u5728\u505a\u529f\u80fd\u6d4b\u8bd5\u8fd8\u662f\u81ea\u52a8\u5316\u6d4b\u8bd5\uff0c\u6700\u540e\u4e00\u6b65\u9700\u8981\u62ff\u5b9e\u9645\u7ed3\u679c\u4e0e\u9884\u671f\u8fdb\u884c\u6bd4\u8f83\u3002\u8fd9\u4e2a\u6bd4\u8f83\u7684\u79f0\u4e4b\u4e3a\u65ad\u8a00\u3002<\/p>\n<p>\u6211\u4eec\u901a\u5e38\u53ef\u4ee5\u901a\u8fc7\u83b7\u53d6title\u3001URL\u548ctext\u7b49\u4fe1\u606f\u8fdb\u884c\u65ad\u8a00\u3002text\u65b9\u6cd5\u5728\u524d\u9762\u5df2\u7ecf\u8bb2\u8fc7\uff0c\u5b83\u7528\u4e8e\u83b7\u53d6\u6807\u7b7e\u5bf9\u4e4b\u95f4\u7684\u6587\u672c\u4fe1\u606f\u3002\u4e0b\u9762\u540c\u6837\u4ee5\u767e\u5ea6\u4e3a\u4f8b\uff0c\u4ecb\u7ecd\u5982\u4f55\u83b7\u53d6\u8fd9\u4e9b\u4fe1\u606f\u3002<\/p>\n<p><!-- more --><\/p>\n<pre><code class=\"language-python\">from selenium import webdriver\nfrom time import sleep\n\ndriver = webdriver.Firefox()\ndriver.get(&quot;https:\/\/www.baidu.com&quot;)\n\nprint(&#039;========Before search========&#039;)\n\n# \u6253\u5370\u5f53\u524d\u9875\u9762title\ntitle = driver.title\nprint(title)\n\n# \u6253\u5370\u5f53\u524d\u9875\u9762URL\nnow_url = driver.current_url\nprint(now_url)\n\ndriver.find_element_by_id(&quot;kw&quot;).send_keys(&quot;selenium&quot;)\ndriver.find_element_by_id(&quot;su&quot;).click()\nsleep(1)\n\nprint(&#039;========After search========&#039;)\n\n# \u518d\u6b21\u6253\u5370\u5f53\u524d\u9875\u9762title\ntitle = driver.title\nprint(title)\n\n# \u6253\u5370\u5f53\u524d\u9875\u9762URL\nnow_url = driver.current_url\nprint(now_url)\n\n# \u83b7\u53d6\u7ed3\u679c\u6570\u76ee\nuser = driver.find_element_by_class_name(&#039;nums&#039;).text\nprint(user)\n\ndriver.quit()<\/code><\/pre>\n<p>\u811a\u672c\u8fd0\u884c\u7ed3\u679c\u5982\u4e0b\uff1a<\/p>\n<pre><code>========Before search========\n\u767e\u5ea6\u4e00\u4e0b\uff0c\u4f60\u5c31\u77e5\u9053\nhttps:\/\/www.baidu.com\/\n========After search========\nselenium_\u767e\u5ea6\u641c\u7d22\nhttps:\/\/www.baidu.com\/s?ie=utf-8&f=8&rsv_bp=0&rsv_idx...\n\u641c\u7d22\u5de5\u5177\n\u767e\u5ea6\u4e3a\u60a8\u627e\u5230\u76f8\u5173\u7ed3\u679c\u7ea65,380,000\u4e2a<\/code><\/pre>\n<ul>\n<li>title\uff1a\u7528\u4e8e\u83b7\u5f97\u5f53\u524d\u9875\u9762\u7684\u6807\u9898<\/li>\n<li>current_url\uff1a\u7528\u6237\u83b7\u5f97\u5f53\u524d\u9875\u9762\u7684URL<\/li>\n<li>text\uff1a\u83b7\u53d6\u641c\u7d22\u6761\u76ee\u7684\u6587\u672c\u4fe1\u606f<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u4e0d\u7ba1\u662f\u5728\u505a\u529f\u80fd\u6d4b\u8bd5\u8fd8\u662f\u81ea\u52a8\u5316\u6d4b\u8bd5\uff0c\u6700\u540e\u4e00\u6b65\u9700\u8981\u62ff\u5b9e\u9645\u7ed3\u679c\u4e0e\u9884\u671f\u8fdb\u884c\u6bd4\u8f83\u3002\u8fd9\u4e2a\u6bd4\u8f83\u7684\u79f0\u4e4b\u4e3a\u65ad\u8a00\u3002 \u6211\u4eec\u901a\u5e38\u53ef\u4ee5\u901a [&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-756","post","type-post","status-publish","format-standard","hentry","category-selenium"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/756","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=756"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/756\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=756"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=756"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=756"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}