{"id":766,"date":"2023-02-26T16:16:03","date_gmt":"2023-02-26T08:16:03","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=766"},"modified":"2023-04-29T16:58:01","modified_gmt":"2023-04-29T08:58:01","slug":"python-selenium-window-screenshot","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/02\/26\/python-selenium-window-screenshot\/","title":{"rendered":"Python Selenium\u7a97\u53e3\u622a\u56fe"},"content":{"rendered":"<p>\u81ea\u52a8\u5316\u7528\u4f8b\u662f\u7531\u7a0b\u5e8f\u53bb\u6267\u884c\u7684\uff0c\u56e0\u6b64\u6709\u65f6\u5019\u6253\u5370\u7684\u9519\u8bef\u4fe1\u606f\u5e76\u4e0d\u5341\u5206\u660e\u786e\u3002\u5982\u679c\u5728\u811a\u672c\u6267\u884c\u51fa\u9519\u7684\u65f6\u5019\u80fd\u5bf9\u5f53\u524d\u7a97\u53e3\u622a\u56fe\u4fdd\u5b58\uff0c\u90a3\u4e48\u901a\u8fc7\u56fe\u7247\u5c31\u53ef\u4ee5\u975e\u5e38\u76f4\u89c2\u5730\u770b\u51fa\u51fa\u9519\u7684\u539f\u56e0\u3002WebDriver\u63d0\u4f9b\u4e86\u622a\u56fe\u51fd\u6570<code>get_screenshot_as_file()<\/code>\u6765\u622a\u53d6\u5f53\u524d\u7a97\u53e3\u3002<\/p>\n<p><!-- more --><\/p>\n<pre><code class=\"language-python\">from selenium import webdriver\nfrom time import sleep\n\ndriver = webdriver.Chrome()\ndriver.get(&#039;http:\/\/www.baidu.com&#039;)\n\ndriver.find_element_by_id(&#039;kw&#039;).send_keys(&#039;appblog.cn&#039;)\ndriver.find_element_by_id(&#039;su&#039;).click()\nsleep(2)\n\n# \u622a\u53d6\u5f53\u524d\u7a97\u53e3\uff0c\u5e76\u6307\u5b9a\u622a\u56fe\u56fe\u7247\u7684\u4fdd\u5b58\u4f4d\u7f6e\ndriver.get_screenshot_as_file(&quot;baidu_img.png&quot;)\n\ndriver.quit()<\/code><\/pre>\n<p>\u811a\u672c\u8fd0\u884c\u5b8c\u6210\u540e\u5728\u9879\u76ee\u6839\u76ee\u5f55\u4e0b\u5373\u53ef\u627e\u5230baidu_img.png\u56fe\u7247\u6587\u4ef6\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u81ea\u52a8\u5316\u7528\u4f8b\u662f\u7531\u7a0b\u5e8f\u53bb\u6267\u884c\u7684\uff0c\u56e0\u6b64\u6709\u65f6\u5019\u6253\u5370\u7684\u9519\u8bef\u4fe1\u606f\u5e76\u4e0d\u5341\u5206\u660e\u786e\u3002\u5982\u679c\u5728\u811a\u672c\u6267\u884c\u51fa\u9519\u7684\u65f6\u5019\u80fd\u5bf9\u5f53\u524d\u7a97\u53e3\u622a\u56fe\u4fdd\u5b58 [&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-766","post","type-post","status-publish","format-standard","hentry","category-selenium"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/766","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=766"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/766\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=766"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=766"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=766"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}