{"id":274791,"date":"2021-01-12T15:42:54","date_gmt":"2021-01-12T07:42:54","guid":{"rendered":"http:\/\/4563.org\/?p=274791"},"modified":"2021-01-12T15:42:54","modified_gmt":"2021-01-12T07:42:54","slug":"%e6%80%8e%e4%b9%88%e7%94%a8-bash-%e7%9a%84%e6%ad%a3%e5%88%99%e8%a1%a8%e8%be%be%e5%bc%8f%e4%bb%8e%e4%b8%80%e5%a4%a7%e5%a0%86%e8%b6%85%e9%93%be%e6%8e%a5%e4%b8%ad%e7%ad%9b%e9%80%89%e4%b8%ad%e6%8c%87","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=274791","title":{"rendered":"\u600e\u4e48\u7528 bash \u7684\u6b63\u5219\u8868\u8fbe\u5f0f\u4ece\u4e00\u5927\u5806\u8d85\u94fe\u63a5\u4e2d\u7b5b\u9009\u4e2d\u6307\u5b9a\u7684\u94fe\u63a5\uff1f"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  \u600e\u4e48\u7528 bash \u7684\u6b63\u5219\u8868\u8fbe\u5f0f\u4ece\u4e00\u5927\u5806\u8d85\u94fe\u63a5\u4e2d\u7b5b\u9009\u4e2d\u6307\u5b9a\u7684\u94fe\u63a5\uff1f               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : gnomeek <\/span>  <span><i><\/i> 0<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>\u8bf7\u6559\u5927\u4f6c\u4eec\u4e00\u4e2a regex \u7684\u95ee\u9898\u3002\u80cc\u666f\u662f\u4e00\u4e2a\u53ea\u542b\u5927\u91cf\u8d85\u94fe\u63a5\u7684 html \u7f51\u9875\uff0c\u9700\u8981\u4ece\u8fd9\u4e9b\u8d85\u94fe\u63a5\u4e2d\u7b5b\u9009\u51fa\u6307\u5b9a\u7684\u94fe\u63a5\u5e76\u4e0b\u8f7d\uff0c\u5927\u6982\u7684\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre><code>wget www.abc.com\/result.html res_url=$something wget $res_url <\/code><\/pre>\n<p>result.html \u957f\u4e0b\u9762\u8fd9\u6837\uff1a<\/p>\n<blockquote>\n<p>&lt;a href=&#8217;www.abc.com\/file1&#8242;&gt;file1&lt;br\/&gt;&lt;br\/&gt;&lt;a href=&#8217;www.abc.com\/file2&#8242;&gt;file2&lt;br\/&gt;&lt;br\/&gt;&lt;a href=&#8217;www.abc.com\/file3&#8242;&gt;file3&lt;br\/&gt;&lt;br\/&gt;&lt;a href=&#8217;www.abc.com\/file4&#8242;&gt;file4&lt;br\/&gt;&lt;br\/&gt;<\/p>\n<\/blockquote>\n<p>res_url \u957f\u8fd9\u6837\uff1a<\/p>\n<blockquote>\n<p>www.abc.com\/file3<\/p>\n<\/blockquote>\n<p>\u6211\u4e4b\u524d\u7684\u65b9\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre><code>tmp=$(grep -o \"file2.*\/file3\" result.html) res_url=$(echo \"$tmp\" | grep -o \"http.*\/file3\") <\/code><\/pre>\n<p>\u4f46\u662f\u73b0\u5728\u7684\u95ee\u9898\u662f\uff0c\u8fd9\u4e9b\u8d85\u94fe\u63a5\u7684\u987a\u5e8f\u662f\u53d8\u5316\u7684\uff0c\u6709\u53ef\u80fd file3 \u7684\u94fe\u63a5\u4e0b\u6b21\u5c31\u5728 file2 \u4e4b\u524d\uff0c\u4e0a\u9762\u7684\u65b9\u6cd5\u4e0d\u592a\u7a33\u5b9a\u3002\u8bf7\u6559\u5404\u4f4d\u5927\u4f6c\uff0c\u600e\u4e48\u4f7f\u7528 shell \u7684\u6b63\u5219\u8868\u8fbe\u5f0f\u6765\u4ece\u5982\u4e0b\u7684\u539f\u59cb\u5b57\u7b26\u4e32\u4e2d\u63d0\u53d6\u51fa\u76ee\u6807\u5b57\u7b26\u4e32\u5462\uff1f<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>9<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"4911119\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : TimePPT <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4e13\u4e1a\u7684\u4e8b\u4ea4\u7ed9\u4e13\u4e1a\u7684\u5de5\u5177\u5427\uff0c\u8fd9\u4e2a\u9700\u6c42 lxml \u8fd9\u79cd python \u89e3\u6790\u5e93\u51e0\u884c\u7684\u4e8b                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4911120\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : wd <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6211\u770b\u4e86\u4e00\u4f1a\u5b9e\u5728\u770b\u4e0d\u61c2\u4e3b\u7684\u95ee\u9898.. \u653e\u5f03\u4e86                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4911121\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : gnomeek <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @wd hhh- -\u5176\u5b9e\u5c31\u662f\u4e00\u4e2a jenkins \u7684 build_result.html\uff0c\u9700\u8981\u5199\u4e00\u4e2a\u811a\u672c\u6765\u63d0\u53d6\u51fa build \u4e2d\u7684\u4e00\u4e9b\u6587\u4ef6\uff08\u4e5f\u5c31\u662f\u6307\u5b9a\u7684\u8d85\u94fe\u63a5\uff09                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4911122\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : gnomeek <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @TimePPT \u662f\u7684\uff0c\u7528 python \u4f1a\u65b9\u4fbf\u5f88\u591a\u3002\u4e0d\u8fc7\u8fd8\u662f\u7528 bash \u89e3\u51b3\u4e86- -\u770b\u6765\u8fd8\u662f\u4e0d\u80fd\u52a0\u73ed\uff0c\u8111\u5b50\u90fd\u5feb\u6210\u6d46\u7cca\u4e86                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4911123\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : gnomeek <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u89e3\u51b3\u4e86<br \/>&#8220;`<br \/> wget www.abc.com\/build_result.html<br \/> array=($(grep -ohr -E &#8220;https?:\/\/[a-zA-Z0-9.\/_&amp;[email&#160;protected]$%?~#-]*&#8221; build_result.html))<br \/> for element in ${array[@]}<br \/> do<br \/> if [[ &#8220;$element&#8221; == *&#8221;\/file2&#8243;* ]]; then<br \/> wget $element<br \/> fi<br \/> done<br \/>&#8220;`                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4911124\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Lax <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6700\u597d\u7528\u4e13\u4e1a\u7684\u5de5\u5177\uff0c\u4f7f\u7528 xpath \u6216\u8005 css selector \u7684\u5e93\u53bb\u9009\u62e9\u5bf9\u5e94\u7684\u5143\u7d20\u3002<\/p>\n<p>\u5982\u679c\u975e\u8981\u7528\u6b63\u5219\uff0c\u5c31\u597d\u597d\u770b\u770b\u6587\u6863\u3002\u5177\u4f53\u5230\u8fd9\u91cc\uff0c\u53ef\u4ee5\u5148\u628a\u5168\u90e8\u94fe\u63a5\uff08 href \uff09\u5339\u914d\u51fa\u6765\uff0c\u518d\u8fdb\u884c\u5904\u7406\u3002<\/p>\n<p>&gt; grep -i -E -o &#8220;href='([^&#8217;]*file[0-9]*)'&#8221;                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4911125\" 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>                                                             \u95ee\u9898\u662f\u4f60\u7684\u6b63\u5219\u4e3a\u4f55\u8fd9\u6837\u5199\uff1f\u5173 file2 \u4ec0\u4e48\u4e8b\uff1f\u80fd\u5339\u914d href&#8230;file3 \u8fd9\u6bb5\u5c31\u591f\u4e86\u554a<br \/>\u81ea\u5df1\u641c\u7d22\u4e00\u4e0b\u6b63\u5219\u7684\u8d2a\u5a6a\u3001\u975e\u8d2a\u5a6a                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4911126\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : gnomeek <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @imn1 \u4f46\u662f\u4ed6\u4eec\u7684 prefix \u662f\u4e00\u6a21\u4e00\u6837\uff0c\u4e14\u4e0d\u786e\u5b9a\u7684\u3002\u6bd4\u5982\u4f1a\u6709\u4e00\u4e9b\u7248\u672c\u53f7\u7684\u4fe1\u606f\uff0c\u5982 www.abc.com\/123\/file1.txt \u8fd9\u6837\uff0c\u6bcf\u6b21\u7684\u7248\u672c\u53f7\u90fd\u4e0d\u4e00\u6837\uff0c\u6ca1\u6cd5\u90a3\u4e48\u7cbe\u7ec6\u7684\u5339\u914d                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4911127\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : gnomeek <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @Lax \u5bf9- -\u662f\u6211\u8111\u5b50\u6ca1\u8f6c\u8fc7\u6765\uff0cgrep \u5b58\u6210 array\uff0c\u518d\u904d\u5386\u7528 grep \u67e5\u8be2 substring \u5c31\u597d\u4e86                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>\u600e\u4e48\u7528 bash \u7684\u6b63\u5219\u8868\u8fbe\u5f0f\u4ece\u4e00&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\/274791"}],"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=274791"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/274791\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=274791"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=274791"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=274791"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}