{"id":291473,"date":"2024-05-06T21:34:52","date_gmt":"2024-05-06T13:34:52","guid":{"rendered":"https:\/\/lrxjmw.cn\/zlhjxcgbshyy.html"},"modified":"2024-05-06T21:34:52","modified_gmt":"2024-05-06T13:34:52","slug":"zlhjxcgbshyy","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/zlhjxcgbshyy.html","title":{"rendered":"\u5728Linux\u73af\u5883\u4e0b\u6210\u529f\u90e8\u7f72\u548c\u5e94\u7528PhantomJS\uff1a\u5f3a\u5927\u7684\u65e0\u5934\u6d4f\u89c8\u5668\u6280\u672f\u89e3\u6790\u53ca\u5e94\u7528\u6307\u5357"},"content":{"rendered":"

\u4f34\u968f\u7740\u4e92\u8054\u7f51\u6280\u672f\u4e0d\u65ad\u53d1\u5c55\uff0cweb\u5f00\u53d1\u548c\u81ea\u52a8\u5316\u6d4b\u8bd5\u6210\u4e3a\u4e86\u8f6f\u4ef6\u7814\u53d1\u7684\u5173\u952e\u529b\u91cf\u3002\u5728\u6b64\u4e4b\u4e2d\uff0cPhantomJS\u4f5c\u4e3a\u4e1a\u754c\u7fd8\u695a\u7684\u65e0\u5934\u6d4f\u89c8\u5668linux\u7cfb\u7edf\u547d\u4ee4\uff0c\u5176\u4ef7\u503c\u4e0d\u53ef\u5ffd\u89c6\u3002\u672c\u7bc7\u6587\u7ae0\u5c06\u8be6\u7ec6\u9610\u8ff0\u5982\u4f55\u5728Linux<\/a>\u73af\u5883\u4e0b\u6210\u529f\u90e8\u7f72\u5e76\u8fd0\u7528PhantomJS\u3002<\/p>\n

1.PhantomJS\u7b80\u4ecb<\/b><\/p>\n

\u4ee5WebKit\u4e3a\u6838\u5fc3\uff0cPhantomJS\u662f\u4e00\u6b3e\u5177\u5907\u5f3a\u5927\u529f\u80fd\u7684\u670d\u52a1\u5668\u7aefJavaScriptAPI\uff0c\u4e13\u6ce8\u4e8e\u901a\u8fc7\u65e0\u754c\u9762\u8fd0\u884c\u6a21\u5f0f\u5b9e\u65bd\u7f51\u9875\u6d3b\u52a8\u3002\u5176\u5e7f\u6cdb\u9002\u7528\u6027\u53ca\u7075\u6d3b\u7279\u6027\uff0c\u6db5\u76d6\u4e86DOM\u64cd\u4f5c\u3001CSS\u9009\u62e9\u4ee5\u53caJSON\u7b49\u591a\u9879Web\u6280\u672f\u6807\u51c6\u3002\u56e0\u6b64\uff0c\u65e0\u8bba\u662f\u5728Web\u5f00\u53d1\u8fd8\u662f\u81ea\u52a8\u5316\u6d4b\u8bd5\u9886\u57df\uff0c\u8fd9\u4e00\u5de5\u5177\u90fd\u9887\u5177\u5f71\u54cd\u529b\u3002<\/p>\n

PhantomJS\u7684\u7279\u70b9\u5305\u62ec\u4f46\u4e0d\u9650\u4e8e\uff1a<\/p>\n

-\u652f\u6301Web\u9875\u9762\u622a\u56fe<\/p>\n

-\u652f\u6301\u9875\u9762\u5185\u5bb9\u6293\u53d6<\/p>\n

-\u652f\u6301\u9875\u9762\u81ea\u52a8\u5316\u64cd\u4f5c<\/p>\n

-\u652f\u6301\u9875\u9762\u6027\u80fd\u5206\u6790<\/p>\n

-\u652f\u6301\u591a\u79cd\u6587\u4ef6\u683c\u5f0f\u7684\u5bfc\u51fa<\/p>\n

2.Linux\u4e0bPhantomJS\u7684\u5b89\u88c5<\/b><\/p>\n

\u5728Linux\u73af\u5883\u4e2d\uff0c\u7528\u6237\u53ef\u9009\u62e9\u901a\u8fc7\u5305\u7ba1\u7406\u5668\u6216\u76f4\u63a5\u624b\u5de5\u7f16\u8bd1\u4ee5\u5b9e\u73b0\u5bf9PhantomJS\u7684\u90e8\u7f72\u3002<\/p>\n

\u901a\u8fc7\u5305\u7ba1\u7406\u5668\u5b89\u88c5<\/p>\n

\u5bf9\u4e8e\u7279\u5b9a\u7684Linux\u53d1\u884c\u7248\u672c,\u5176\u81ea\u5e26\u7684\u8f6f\u4ef6\u53d1\u5e03\u7cfb\u7edf<\/a>\u80fd\u591f\u8fc5\u901f\u5730\u90e8\u7f72PhantomJS\u3002\u4f8b\u5982\u5728Ubuntu\u73af\u5883\u4e0b\uff0c\u6267\u884c\u7b80\u5355\u7684apt-get\u547d\u4ee4<\/a>\u5c31\u53ef\u4ee5\u5b8c\u6210\u6b64\u9879\u4efb\u52a1\u3002<\/p>\n

\n

bash\n\u4f7f\u7528apt\u5b89\u88c5PhantomJS\u3002\n<\/pre>\n<\/p>\n

\u800c\u5728CentOS\u7cfb\u7edf\u4e2d\uff0c\u5219\u53ef\u4ee5\u4f7f\u7528yum\u547d\u4ee4\u8fdb\u884c\u5b89\u88c5\uff1a<\/p>\n

sudoyuminstallphantomjs<\/p>\n

\u51ed\u501f\u8f6f\u4ef6\u5305\u7ba1\u7406\u5668\uff0c\u7528\u6237\u5f97\u4ee5\u8f7b\u677e\u5b9e\u73b0\u5404\u7c7b\u64cd\u4f5c\uff0c\u5e76\u5b9e\u73b0\u4f9d\u8d56\u5173\u7cfb\u81ea\u52a8\u5316\u89e3\u6790\uff0c\u5bf9\u4e8e\u521d\u5b66\u8005\u6216\u9700\u8fc5\u901f\u6784\u5efa\u9879\u76ee\u73af\u5883\u7684\u4eba\u58eb\u800c\u8a00\u5c24\u4e3a\u5408\u9002\u3002<\/p>\n

\u624b\u52a8\u7f16\u8bd1\u5b89\u88c5<\/p>\n

\u82e5\u9700\u8981\u66f4\u52a0\u7075\u6d3b\u63a7\u5236\u548c\u5b9a\u5236PhantomJS\u7684\u5b89\u88c5\uff0c\u60a8\u8fd8\u53ef\u4ee5\u9009\u62e9\u624b\u52a8\u7f16\u8bd1\u8fdb\u884c\u5b89\u88c5\u3002\u4e0e\u81ea\u52a8\u5b89\u88c5\u76f8\u6bd4\uff0c\u8fd9\u4e2a\u6d41\u7a0b\u9700\u8981\u60a8\u5bf9\u6e90\u4ee3\u7801\u6709\u6df1\u5165\u4e86\u89e3\uff0c\u4f46\u80fd\u63d0\u4f9b\u66f4\u5927\u7684\u81ea\u7531\u5ea6\uff0c\u8ba9\u60a8\u80fd\u591f\u6839\u636e\u5b9e\u9645\u9700\u6c42\u8c03\u6574\u7f16\u8bd1\u53c2\u6570\u3002\u4ee5\u4e0b\u662f\u8be6\u7ec6\u7684\u64cd\u4f5c\u6b65\u9aa4\uff1a<\/p>\n

\u8bf7\u8bbf\u95eePhantomJS\u5b98\u65b9\u7f51\u7ad9\u6216\u8005GitHub\u4e0b\u8f7d\u5e76\u5b89\u88c5\u6700\u65b0\u7248\u6e90\u4ee3\u7801\u538b\u7f29\u5305\u3002<\/p>\n

-\u89e3\u538b\u538b\u7f29\u5305\u81f3\u6307\u5b9a\u76ee\u5f55\uff0c\u5e76\u8fdb\u5165\u89e3\u538b\u540e\u7684\u76ee\u5f55\u3002<\/p>\n

-\u6267\u884c\u547d\u4ee4\u8fdb\u884c\u7f16\u8bd1\uff1a<\/p>\n

.\/build.sh<\/p>\n

\u7ecf\u7f16\u8bd1\u6539\u9020\u540e\uff0c\u4f1a\u751f\u6210PhantomJS\u7684\u6267\u884c\u6587\u4ef6\uff0c\u53ea\u9700\u5728\u7cfb\u7edf\u73af\u5883\u53d8\u91cf\u4e2d\u589e\u8bbe\uff0c\u4fbf\u53ef\u8f7b\u677e\u5229\u7528\u3002<\/p>\n

\u5728Linux\u8fd0\u884c\u73af\u5883\u4e2dlinux\u4e32\u53e3\u9a71\u52a8\uff0cphantomJS\u53ef\u4ee5\u901a\u8fc7\u5305\u7ba1\u7406\u5668\u6216\u8005\u624b\u52a8\u7f16\u8bd1\u4e24\u79cd\u65b9\u5f0f\u6765\u5b8c\u6210\u5b89\u88c5\u3002\u9488\u5bf9\u4e2a\u4f53\u9700\u6c42\u53ca\u559c\u597d\uff0c\u7528\u6237\u53ef\u81ea\u7531\u6311\u9009\u6700\u9002\u5b9c\u7684\u5b89\u88c5\u63aa\u65bd\u3002<\/p>\n

3.PhantomJS\u7684\u57fa\u672c\u7528\u6cd5<\/b><\/p>\n

\u5728\u6210\u529f\u5b89\u88c5PhantomJS\u4e4b\u540e\uff0c\u7528\u6237\u53ef\u8fd0\u7528\u5176\u4e2d\u4e30\u5bcc\u7684\u547d\u4ee4\u884c\u7279\u6027\u5f00\u5c55\u5404\u9879\u5de5\u4f5c\u3002\u4ee5\u4e0b\u4e3a\u5177\u4f53\u64cd\u4f5c\u8303\u4f8b\u5c55\u793a\uff1a<\/p>\n

\u8bbf\u95ee\u9875\u9762<\/p>\n

\u501f\u52a9PhantomJS\uff0c\u6211\u4eec\u5f97\u4ee5\u76f4\u63a5\u767b\u5165\u7279\u5b9a\u7f51\u7ad9\uff0c\u4ee5\u83b7\u53d6\u7f51\u9875\u5185\u5bb9\u6216\u6267\u884c\u5176\u5b83\u5fc5\u8981\u7684\u64cd\u4f5c\u3002<\/p>\n

phantomjsscript.js<\/p>\n

\"script.js\"\u811a\u672c\u4e3a\u7f51\u9875\u4ea4\u4e92\u548c\u63a7\u5236\u63d0\u4f9b\u4e86\u5173\u952e\u7684\u89c4\u5b9a\u3002<\/p>\n

\u9875\u9762\u622a\u56fe<\/p>\n

PhantomJS\u53ef\u4ee5\u5bf9\u9875\u9762\u8fdb\u884c\u622a\u56fe\uff0c\u4fdd\u5b58\u4e3a\u56fe\u7247\u6587\u4ef6\uff1a<\/p>\n

\u6211\u4eec\u901a\u8fc7\u4f7f\u7528PhantomJS\u4e2d\u7684rasterize.js\u63d2\u4ef6\uff08\u8bbf\u95ee\u5730\u5740\uff1a\uff09\uff0c\u4ee5\u4fbf\u80fd\u591f\u5bf9\u7f51\u7ad9\u754c\u9762\u751f\u6210\u4e00\u5f20\u540d\u4e3a\"output.png\"\u7684PNG\u56fe\u7247\u5c01\u5b58\u3002<\/p>\n

\u6b64\u9879\u4efb\u52a1\u9700\u8bbf\u95ee\u7f51\u5740\"\",\u83b7\u53d6\u56fe\u7247\u540e\u5b58\u50a8\u81f3output.png\u4ee5\u4f9b\u67e5\u770b\u3002<\/p>\n

\u9875\u9762\u5185\u5bb9\u6293\u53d6<\/p>\n

PhantomJS\u53ef\u6355\u83b7\u5e76\u4ee5\u7eaf\u6587\u672c\u5f62\u5f0f\u5bfc\u51fa\u7f51\u9875\u5185\u5bb9\u3002<\/p>\n

\u5229\u7528PhantomJS\u4e2dextract.js\u7ec4\u4ef6linux phantomjs\u5b89\u88c5<\/strong>\uff0c\u6210\u529f\u83b7\u53d6\u5e76\u89e3\u6790\u4e86\u7f51\u7ad9\u9875\u9762\u7684\u5168\u90e8\u5185\u5bb9\u3002<\/p>\n

\u6b64\u547d\u4ee4\u5c06\u6784\u5efa\u81f3\"\"\u7684\u94fe\u63a5\u5e76\u8bfb\u53d6\u76f8\u5173\u5185\u5bb9\u8fdb\u884c\u5c55\u793a\u89e3\u6790\u3002<\/p>\n

4.PhantomJS\u5728\u81ea\u52a8\u5316\u6d4b\u8bd5\u4e2d\u7684\u5e94\u7528<\/b><\/p>\n

\u5728\u7f51\u9875\u4ea4\u4e92\u7684\u57fa\u7840\u4e0a\uff0cPhantomJS\u5728\u81ea\u52a8\u5316\u6d4b\u8bd5\u4e2d\u5177\u6709\u663e\u8457\u7684\u5e94\u7528\u4ef7\u503c\u3002\u5176\u53ef\u501f\u52a9\u7f16\u5199JavaScript\u811a\u672c\u6765\u6a21\u62df\u7528\u6237\u884c\u4e3a\uff0c\u4ee5\u5b9e\u73b0\u5168\u9762\u800c\u7cbe\u786e\u7684\u6d4b\u8bd5\u81ea\u52a8\u5316\u6d41\u7a0b\u3002<\/p>\n

\u793a\u4f8b\uff1a\u9875\u9762\u6027\u80fd\u6d4b\u8bd5<\/p>\n

\u501f\u52a9PhantomJS\u5de5\u5177\uff0c\u53ef\u5bf9\u7f51\u9875\u8fd0\u884c\u6027\u80fd\u8fdb\u884c\u7cbe\u786e\u4e14\u7ec6\u5fae\u7684\u76d1\u6d4b\uff0c\u5982\u52a0\u8f7d\u65f6\u95f4\u4e0e\u8d44\u6e90\u8bf7\u6c42\u7b49\u6307\u6807\u3002<\/p>\n

```javascript<\/p>\n

\u4ee5\u4e0b\u662f\u4f7f\u7528'webpage'\u5e93\u521b\u5efa\u6d4f\u89c8\u5668\u9875\u9762\u7684\u4ee3\u7801\u793a\u4f8b\uff1a<\/p>\n

\u5c06\u5730\u5740\u8bbe\u5b9a\u4e3a''\u3002<\/p>\n

\u5f53\u7f51\u9875\u52a0\u8f7d\u5b8c\u5168\u65f6\uff0c\u4f1a\u7acb\u5373\u9012\u5f52\u8c03\u7528\u9875\u9762\u7684\u6253\u5f00\u51fd\u6570\u3002<\/p>\n

if(status!=='success'){<\/p>\n

\u63d0\u793a\u65e0\u6cd5\u52a0\u8f7d\u5730\u5740\uff01<\/p>\n

}else{<\/p>\n

\u5728\u4ee3\u7801\u4e2d\uff0c\u5c06title\u7684\u503c\u8d4b\u4e3a\u9875\u9762\u5bf9\u5e94\u51fd\u6570\u7684\u8fd4\u56de\u503c\u3002<\/p>\n

returndocument.title;<\/p>\n

});<\/p>\n

\u5728\u63a7\u5236\u53f0\u4e2d\u8bb0\u5f55\u9875\u9762\u6807\u9898\u4e3a\"title\":<\/p>\n

\u8d44\u6e90\u88ab\u8d4b\u4e88\u53d8\u91cf`resouces`\uff0c\u6e90\u81ea\u9875\u9762\u7684\u5c5e\u6027\u4fe1\u606f\u3002<\/p>\n

\u656c\u8bf7\u63d0\u4f9b\u8be6\u7ec6\u7684\u8d44\u6e90\u8bf7\u6c42\u4fe1\u606f\uff0c\u5c24\u5176\u662f\u5305\u542b\u201cresources\u201d\u548c\"..\"\u7b49\u5173\u952e\u8981\u7d20\u3002<\/p>\n

}<\/p>\n

phantom.exit();<\/p>\n

});<\/p>\n

\u672c\u6bb5\u793a\u4f8b\u4ee3\u7801\u65e8\u5728\u5b9e\u73b0\u5bf9\u6307\u5b9a\u7f51\u9875\u7684\u81ea\u542f\u5e76\u63d0\u4f9b\u8be6\u5c3d\u4fe1\u606f\uff0c\u5305\u62ec\u9875\u9762\u6807\u9898\u53ca\u5fc5\u8981\u8d44\u6e90\u7b49\u3002<\/p>\n

5.\u5e38\u89c1\u95ee\u9898\u4e0e\u89e3\u51b3\u65b9\u6cd5<\/b><\/p>\n

\u5728\u8fd0\u7528PhantomJS\u6280\u672f\u65f6\uff0c\u53ef\u80fd\u9047\u5230\u4ee5\u4e0b\u4e24\u5927\u95ee\u9898\u53ca\u89e3\u51b3\u65b9\u6848\uff1a<\/p>\n

\u95ee\u98981\uff1a\u9875\u9762\u52a0\u8f7d\u7f13\u6162<\/p>\n

\u6539\u5584\u7b56\u7565\uff1a\u4f18\u5316\u7f51\u9875\u67b6\u6784\u5e76\u51cf\u5c11\u8d44\u6e90\u8bf7\u6c42\uff0c\u63d0\u9ad8\u7f51\u9875\u8f7d\u5165\u901f\u5ea6\u3002<\/p>\n

\u95ee\u98982\uff1a\u65e0\u6cd5\u6b63\u5e38\u6e32\u67d3\u9875\u9762<\/p>\n

\u656c\u544a\u7528\u6237\uff1a\u8bf7\u53ca\u65f6\u66f4\u65b0PhantomJS\u7248\u672c\u4ee5\u89e3\u51b3\u95ee\u9898\uff1b\u5982\u65e0\u6cd5\u89e3\u51b3linux phantomjs\u5b89\u88c5<\/strong>\uff0c\u53ef\u786e\u8ba4\u7f51\u7ad9\u662f\u5426\u5b58\u5728\u517c\u5bb9\u6027\u95ee\u9898\u3002<\/p>\n

\u95ee\u98983\uff1a\u811a\u672c\u6267\u884c\u51fa\u9519<\/p>\n

\u89e3\u51b3\u65b9\u6cd5\uff1a\u53ef\u4ee5\u68c0\u67e5\u811a\u672c\u8bed\u6cd5\u9519\u8bef\u3001\u7f51\u7edc\u8fde\u63a5\u662f\u5426\u6b63\u5e38\u7b49\u95ee\u9898\u3002<\/p>\n

6.\u5c0f\u7ed3<\/b><\/p>\n

\u672c\u7bc7\u6587\u7ae0\u5c06\u8be6\u5c3d\u4ecb\u7ecd\u5982\u4f55\u5728Linux\u64cd\u4f5c\u7cfb\u7edf\u4e0a\u6210\u529f\u90e8\u7f72\u53ca\u8fd0\u7528PhantomJS\u5e94\u7528\u7684\u8be6\u7ec6\u6b65\u9aa4\u4ee5\u53ca\u76f8\u5173\u6ce8\u610f\u4e8b\u9879\u3002\u6db5\u76d6\u8be5\u5f3a\u5927\u5de5\u5177\u7684\u7b80\u8981\u6982\u8ff0\u3001\u5b89\u88c5\u8fc7\u7a0b\u53d9\u8ff0\u3001\u57fa\u7840\u64cd\u4f5c\u6307\u5bfc\u3001\u81ea\u52a8\u5316\u6d4b\u8bd5\u5e94\u7528\u6f14\u793a\u4e0e\u5e38\u89c1\u95ee\u9898\u89e3\u51b3\u65b9\u6848\u63a2\u8ba8\u7b49\u591a\u4e2a\u65b9\u9762\u3002\u4f5c\u4e3a\u4e00\u4e2a\u8bbe\u8ba1\u6784\u601d\u5168\u9762\u4e14\u8fd0\u884c\u6548\u80fd\u5353\u8d8a\u7684\u65e0\u5934\u7f51\u9875\u6d4f\u89c8\u5668\uff0cPhantomJS\u81f4\u529b\u4e8e\u7b80\u5316Web\u5f00\u53d1\u53ca\u81ea\u52a8\u5316\u6d4b\u8bd5\u6d41\u7a0b\uff0c\u4ece\u800c\u63d0\u9ad8\u7528\u6237\u4f53\u9a8c\u53ca\u6d4b\u8bd5\u6548\u7387\u3002<\/p>\n

7.\u8bfb\u8005\u4e92\u52a8<\/b><\/p>\n

\u60a8\u5bf9PhantomJS\u7684\u770b\u6cd5\u5982\u4f55\uff1f\u5728\u9879\u76ee\u5b9e\u8df5\u4e2d\u6709\u5426\u4f7f\u7528\uff1f<\/p>\n

\u5728Linux\u64cd\u4f5c\u7cfb\u7edf\u7684\u8fd0\u8425\u671f\u95f4\uff0c\u60a8\u662f\u5426\u66fe\u9047\u5230\u6311\u6218\u5e76\u627e\u5230\u6709\u6548\u89e3\u51b3\u65b9\u6848\uff1f\u8bf7\u5206\u4eab\u60a8\u7684\u5b9d\u8d35\u7ecf\u9a8c\u548c\u89c1\u89e3\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

\u4ee5WebKit\u4e3a\u6838\u5fc3\uff0cPhantomJS\u662f\u4e00\u6b3e\u5177\u5907\u5f3a\u5927\u529f\u80fd\u7684\u670d\u52a1\u5668\u7aefJavaScriptAPI\uff0c\u4e13\u6ce8\u4e8e\u901a\u8fc7\u65e0\u754c\u9762\u8fd0\u884c\u6a21\u5f0f\u5b9e\u65bd\u7f51\u9875\u6d3b\u52a8\u3002\u5728\u6210\u529f\u5b89\u88c5PhantomJS\u4e4b\u540e\uff0c\u7528\u6237\u53ef\u8fd0\u7528\u5176\u4e2d\u4e30\u5bcc\u7684\u547d\u4ee4\u884c\u7279\u6027\u5f00\u5c55\u5404\u9879\u5de5\u4f5c\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[988],"tags":[999],"class_list":["post-291473","post","type-post","status-publish","format-standard","hentry","category-tougao","tag-999"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/291473","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=291473"}],"version-history":[{"count":0,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/291473\/revisions"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=291473"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=291473"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=291473"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}