phantomjs 抓取、截图中文网站乱码的问题的解决

用phantomjs抓取html乱码的解决方案:

phantomjs --output-encoding=gbk test.js http://webscan.360.cn/index/checkwebsite?url=www.coding123.net

https://blog.csdn.net/kaosini/article/details/47252457

这两个参数可以指定编码 ...

--output-encoding=encoding sets the encoding used for terminal output (default is utf8).
--script-encoding=encoding sets the encoding used for the starting script (default is utf8).

设置成 GBK 就可以了 ...

或者

phantom.outputEncoding="gbk";

用phantomjs截图时中文乱码的解决方案:

用phantomjs去截取中文页面的网站可能会出现乱码的情况,也就是截图中中文的位置全是方框。
解决办法就是安装字体。
在centos中执行:yum install bitmap-fonts bitmap-fonts-cjk
在ubuntu中执行:sudo apt-get install xfonts-wqy
这样再去截图中文的页面就不会出现一堆的方框了。

猜你喜欢

转载自www.cnblogs.com/shenwenkai/p/9213312.html