{"id":200432,"date":"2020-11-14T19:04:28","date_gmt":"2020-11-14T11:04:28","guid":{"rendered":"http:\/\/4563.org\/?p=200432"},"modified":"2020-11-14T19:04:28","modified_gmt":"2020-11-14T11:04:28","slug":"python-%e5%bc%82%e5%b8%b8%e5%a4%84%e7%90%86%e9%a3%8e%e6%a0%bc","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=200432","title":{"rendered":"Python \u5f02\u5e38\u5904\u7406\u98ce\u683c"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  Python \u5f02\u5e38\u5904\u7406\u98ce\u683c               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : bbxiong <\/span>  <span><i><\/i> 3<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>selenium api \u57fa\u672c\u5168\u90fd\u4f1a\u629b\u5f02\u5e38<\/p>\n<p>\u6bd4\u5982<\/p>\n<p>if driver.find_element_by_class_name(&#8220;general-error&#8221;): print(&#8220;\u767b\u5f55\u9519\u8bef&#8221;)<\/p>\n<p>\u5fc5\u987b\u8981\u5199\u6210\u5982\u4e0b try: if driver.find_element_by_class_name(&#8220;general-error&#8221;): print(&#8220;\u767b\u5f55\u9519\u8bef&#8221;) except: pass<\/p>\n<p>\u6240\u6709\u5e38\u7528 api \u90fd\u4f1a\u629b\u51fa\u5f02\u5e38,\u6bcf\u4e2a find_element_by_xxx \u90fd\u5fc5\u987b\u653e\u5728 try except \u5c01\u88c5\u6210\u51fd\u6570,\u663e\u5f97\u4ee3\u7801\u81c3\u80bf\u4e0d\u582a&#8230;<\/p>\n<p>\u662f\u4e0d\u662f\u6211\u7684\u98ce\u683c\u6709\u95ee\u9898,\u8bf7\u6559\u4e0b\u5927\u5bb6\u90fd\u600e\u4e48\u5904\u7406\u8fd9\u79cd\u60c5\u51b5\u7684.<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>7<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"4279333\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : imn1 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u8fd9\u79cd\u60c5\u51b5\u6211\u9009\u62e9\u6362\u4e2a\u5199\u6cd5\uff0c\u4f8b\u5982\u5176\u4ed6\u6a21\u5757<\/p>\n<p>\u5b9e\u9645\u4e0a\u6211\u90fd\u6ca1\u7528\u8fc7 selenium api\uff0c\u90fd\u4e0d\u77e5\u9053\u4f1a\u629b\u51fa\u5f02\u5e38\uff0c\u6211\u662f\u83b7\u53d6 content \u7136\u540e\u7528\u5176\u4ed6 parser \u6a21\u5757\u5904\u7406\u7684<\/p>\n<p>\u5982\u679c\u4e0d\u53ef\u907f\u514d\u975e\u8981\u7528\u67d0\u4e2a\u6a21\u5757\uff0c\u5b83\u53c8\u5bb9\u6613\u629b\u51fa\u5f02\u5e38\uff0c\u6211\u4f1a\u5199\u4e2a\u7c7b\u7ee7\u627f\u8fc7\u6765\uff0c\u6216\u8005\u95ed\u5305\uff0c\u628a\u5f02\u5e38\u96c6\u4e2d\u5904\u7406                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4279334\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : happinessnch <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5f02\u5e38\u5904\u7406\uff0c\u548c\u4e1a\u52a1\u903b\u8f91\u6ca1\u6709\u5173\u7cfb\uff0c\u548b\u4e00\u770b\u597d\u50cf\u5f88\u81c3\u80bf\uff0c\u597d\u591a\u5730\u65b9\u8981 try catch\uff0c<br \/>\u5b9e\u9645\u4e0a\u5f02\u5e38\u5904\u7406\u591a\u4e86\u6162\u6162\u4e5f\u5c31\u4e60\u60ef\u4e86\uff0c\u6839\u636e\u4e0d\u540c\u5f02\u5e38\u505a\u4e00\u4e9b\u5b9a\u5236\u5316\u7684\u5904\u7406\uff0c<br \/>\u7edd\u5927\u591a\u6570\u5f02\u5e38\u662f\u4e0d\u5e94\u8be5\u76f4\u63a5 pass \u7684\uff0c\u4f46\u662f\u5b9e\u9645\u5f00\u53d1\u65f6\uff0c\u6bcf\u4e2a\u5f02\u5e38\u90fd\u5904\u7406\u786e\u5b9e\u6709\u70b9\u8fc7\u4e8e\u82db\u6c42\u4e86\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4279335\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : no1xsyzy <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u8fd9\u4e2a\u662f\u8bbe\u8ba1\u95ee\u9898\uff0c\u4e0d\u8fc7\u4f60\u8fd9\u8fb9\u4f3c\u4e4e\u4e5f\u53ef\u4ee5\u66f4\u6b63\u4ea4\u5730\u62bd\u8c61<\/p>\n<p>def finds(driver, **kwargs): <br \/>\u3000\u3000 try:<br \/>\u3000\u3000\u3000\u3000 return driver.find_element(&#8230;) # TODO: implement it<br \/>\u3000\u3000 except:<br \/>\u3000\u3000\u3000\u3000 return None<\/p>\n<p>\u8fd9\u6837\u7684\u8bdd\u4f60\u4ee5\u540e\u5c31\u53ef\u4ee5<br \/>if finds(driver, class_name=&#8221;loaderIcon&#8221;):<br \/>\u3000\u3000&#8230;<br \/>elif finds(driver, class_name=&#8221;ut-tab-bar&#8221;):<br \/>\u3000\u3000&#8230;<br \/>&#8230;                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4279336\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : no1xsyzy <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @happinessnch BTW \u5982\u679c\u903b\u8f91\u4e0a\u786e\u5b9e\u5e94\u4e0d\u5904\u7406\uff0c\u6211\u63a8\u8350 with contextlib.suppress<br \/>\u5982\u679c\u6682\u65f6\u4e0d\u4f5c\u5904\u7406\uff0c\u6211\u63a8\u8350 except: pass # TODO: handle this                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4279337\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : bbxiong <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @no1xsyzy \u8fd9\u79cd\u8bbe\u8ba1\u65b9\u5f0f\u7528\u8d77\u6765\u6bd4\u8f83\u65b9\u4fbf,\u5176\u5b9e\u6211\u5947\u602a\u7684\u4e3a\u5565 selenium \u8bbe\u8ba1\u8fd9\u4e9b api \u8981\u629b\u5f02\u5e38,\u800c\u4e0d\u662f\u627e\u4e0d\u5230\u8fd4\u56de None                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4279338\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : imn1 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @bbxiong #5<br \/>\u6a21\u5757\u4e00\u822c\u662f\u901a\u7528\u7684\uff0c\u6cdb\u8003\u8651<\/p>\n<p>\u4f8b\u5982\u67d0\u4e2a exif \u6a21\u5757\uff0c\u91cc\u9762\u4e25\u683c\u6267\u884c exif \u89c4\u8303\uff0cdump \u7684\u65f6\u5019\u4e00\u4e2a\u503c\u9519\u4e86\u5c31\u4f1a\u629b\u5f02\u5e38<br \/>\u672c\u6765 exif \u6709\u51e0\u767e\u6761\uff0c\u4e00\u6761\u9519\u8bef\u5e76\u4e0d\u5f71\u54cd\u5176\u4ed6\u8bfb\u53d6\uff0c\u4e5f\u4e0d\u5f71\u54cd\u56fe\u7247\u672c\u8eab\u663e\u793a\uff0c\u6279\u91cf\u5904\u7406\uff08\u4e0a\u5343\u4e2a\u56fe\u7247\uff09\u9047\u5230\u9519\u8bef\u53ef\u4ee5\u8df3\u8fc7\u5c31\u884c\u4e86\uff0c\u9010\u4e2a\u5904\u7406\u5f02\u5e38\u786e\u5b9e\u9ebb\u70e6<br \/>\u4f46\u4eba\u5bb6\u6309\u7167\u89c4\u8303\u505a\uff0c\u4e5f\u4e0d\u80fd\u8bf4\u4eba\u5bb6\u505a\u9519\u4e86\uff0c\u56e0\u4e3a\u9075\u5b88\u89c4\u8303\u603b\u662f\u6b63\u786e\u7acb\u573a\uff0c\u53ea\u80fd\u81ea\u5df1\u7ee7\u627f\u4fee\u6539\u4ee5\u9002\u5e94\u81ea\u5df1\u7684\u9700\u6c42                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4279339\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : no1xsyzy <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @bbxiong \u53d1\u73b0\u6211\u53ef\u80fd\u5355\u4f4d\u5199\u4e86\u4e00\u5806\u5fd8\u4e86\u53d1\u2026\u2026<br \/>\u5e94\u8be5\u5b83\u7684\u8fd9\u4e9b API \u5c31\u662f\u8bbe\u8ba1\u4e3a\u94fe\u5f0f\u8c03\u7528\u7684\uff0c\u90a3\u663e\u7136\u62a5\u4e00\u4e2a\u201c\u5143\u7d20\u627e\u4e0d\u5230\u201d\u7684\u9519\u6bd4\u201cNoneType \u6ca1\u6709\u6b64\u5c5e\u6027\u201d\u7684\u9519\u66f4\u5408\u7406\u3002<br \/>\u4e0d\u8fc7\uff0c\u6211\u8bbe\u8ba1\u7684\u8bdd\u4f1a\u8bbe\u8ba1\u4e24\u5957 API\uff0c\u4e00\u4e2a\u66f4\u7b80\u6d01\u7684\u5f15\u53d1\u5f02\u5e38\uff0c\u66f4\u5570\u55e6\u7684\u7ed9 None\uff0c\u5f62\u5982 dct[&#8216;key&#8217;] v.s. dct.get(&#8216;key&#8217;)<br \/>\u6216\u8005\u63d0\u4f9b\u4e00\u4e2a\u53c2\u6570\u6765\u8868\u793a\u9ed8\u8ba4\u503c\uff0c\u4e0d\u63d0\u4f9b\u5c31\u5f15\u53d1\u5f02\u5e38\uff0c\u5f62\u5982 dct.pop(&#8216;key&#8217;, None) v.s. dct.pop(&#8216;key&#8217;)                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>Python \u5f02\u5e38\u5904\u7406\u98ce\u683c \u8cc7\u6df1\u5927&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/200432"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=200432"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/200432\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=200432"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=200432"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=200432"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}