在这篇文章中,我们将带领您了解PhantomJS:管道输入的全貌,包括管道输入是什么的相关情况。同时,我们还将为您介绍有关16、web爬虫讲解2—PhantomJS虚拟浏览器+selenium模块操作
在这篇文章中,我们将带领您了解PhantomJS:管道输入的全貌,包括管道输入是什么的相关情况。同时,我们还将为您介绍有关16、web爬虫讲解2—PhantomJS虚拟浏览器+selenium模块操作PhantomJS、centos 7安装phantomjs、CentOS NodeJS PhantomJS PhearJS 失败的尝试……、java.lang.IllegalStateException:该驱动程序不可执行:/resources/phantomjs-2.1.1-linux-x86_64/bin/phantomjs的知识,以帮助您更好地理解这个主题。
本文目录一览:- PhantomJS:管道输入(管道输入是什么)
- 16、web爬虫讲解2—PhantomJS虚拟浏览器+selenium模块操作PhantomJS
- centos 7安装phantomjs
- CentOS NodeJS PhantomJS PhearJS 失败的尝试……
- java.lang.IllegalStateException:该驱动程序不可执行:/resources/phantomjs-2.1.1-linux-x86_64/bin/phantomjs
PhantomJS:管道输入(管道输入是什么)
我正在尝试使用PhantomJS将html页面呈现为pdf。我不想将文件写入磁盘,内存中有html,并且内存中需要pdf。
使用从Pooria阿芝米的出色答卷,在这个问题,我能够从命名管道获取PDF。当另一端尝试相同时(用命名管道替换输入文件),我最终得到一个空白的pdf。
这就是我现在正在做的(简体):
mkfifo in_pipe.html out_pipe.pdf./phantomjs rasterize.js in_pipe.html out_pipe.pdf
然后在另一个终端:
echo ''<center>hey!</center>'' > in_pipe.htmlcat out_pipe.pdf > out.pdf
文件out.pdf已创建,但为空白。我想念什么吗?
答案1
小编典典您可以直接在PhantomJS中非常简单地完成所要查找的内容(只是没有真正记录在案)。
var page = require(''webpage'').create(), fs = require(''fs'');page.viewportSize = { width: 600, height: 600 };page.paperSize = { format: ''Letter'', orientation: ''portrait'', margin: ''1cm'' };page.content = fs.read(''/dev/stdin'');window.setTimeout(function() { page.render(''/dev/stdout'', { format: ''pdf'' }); phantom.exit();}, 1);
(如果您有需要加载的图像等,则可能需要增加超时时间。)
HTML输入标准输入,PDF二进制输出标准输出。您可以像这样测试它:
echo "<b>test</b>" | phantomjs makepdf.js > test.pdf && open test.pdf
16、web爬虫讲解2—PhantomJS虚拟浏览器+selenium模块操作PhantomJS
【百度云搜索,搜各种资料:http://www.bdyss.cn】
【搜网盘,搜各种资料:http://www.swpan.cn】
PhantomJS虚拟浏览器
phantomjs 是一个基于js的webkit内核无头浏览器 也就是没有显示界面的浏览器,利用这个软件,可以获取到网址js加载的任何信息,也就是可以获取浏览器异步加载的信息
下载网址:http://phantomjs.org/download... 下载对应系统版本
下载后解压PhantomJS文件,将解压文件夹,剪切到python安装文件夹
然后将PhantomJS文件夹里的bin文件夹添加系统环境变量
cdm 输入命令:PhantomJS 出现以下信息说明安装成功
selenium模块是一个python操作PhantomJS软件的一个模块
selenium模块PhantomJS软件
webdriver.PhantomJS()实例化PhantomJS浏览器对象
get(''url'')访问网站
find_element_by_xpath(''xpath表达式'')通过xpath表达式找对应元素
clear()清空输入框里的内容
send_keys(''内容'')将内容写入输入框
click()点击事件
get_screenshot_as_file(''截图保存路径名称'')将网页截图,保存到此目录
page_source获取网页htnl源码
quit()关闭PhantomJS浏览器
#!/usr/bin/env python
# -*- coding:utf8 -*-
from selenium import webdriver #导入selenium模块来操作PhantomJS
import os
import time
import re
llqdx = webdriver.PhantomJS() #实例化PhantomJS浏览器对象
llqdx.get("https://www.baidu.com/") #访问网址
# time.sleep(3) #等待3秒
# llqdx.get_screenshot_as_file(''H:/py/17/img/123.jpg'') #将网页截图保存到此目录
#模拟用户操作
llqdx.find_element_by_xpath(''//*[@id="kw"]'').clear() #通过xpath表达式找到输入框,clear()清空输入框里的内容
llqdx.find_element_by_xpath(''//*[@id="kw"]'').send_keys(''叫卖录音网'') #通过xpath表达式找到输入框,send_keys()将内容写入输入框
llqdx.find_element_by_xpath(''//*[@id="su"]'').click() #通过xpath表达式找到搜索按钮,click()点击事件
time.sleep(3) #等待3秒
llqdx.get_screenshot_as_file(''H:/py/17/img/123.jpg'') #将网页截图,保存到此目录
neir = llqdx.page_source #获取网页内容
print(neir)
llqdx.quit() #关闭浏览器
pat = "<title>(.*?)</title>"
title = re.compile(pat).findall(neir) #正则匹配网页标题
print(title)
PhantomJS浏览器伪装,和滚动滚动条加载数据
有些网站是动态加载数据的,需要滚动条滚动加载数据
实现代码
DesiredCapabilities 伪装浏览器对象
execute_script()执行js代码
current_url获取当前的url
#!/usr/bin/env python
# -*- coding:utf8 -*-
from selenium import webdriver #导入selenium模块来操作PhantomJS
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities #导入浏览器伪装模块
import os
import time
import re
dcap = dict(DesiredCapabilities.PHANTOMJS)
dcap[''phantomjs.page.settings.userAgent''] = (''Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.221 Safari/537.36 SE 2.X MetaSr 1.0'')
print(dcap)
llqdx = webdriver.PhantomJS(desired_capabilities=dcap) #实例化PhantomJS浏览器对象
llqdx.get("https://www.jd.com/") #访问网址
#模拟用户操作
for j in range(20):
js3 = ''window.scrollTo(''+str(j*1280)+'',''+str((j+1)*1280)+'')''
llqdx.execute_script(js3) #执行js语言滚动滚动条
time.sleep(1)
llqdx.get_screenshot_as_file(''H:/py/17/img/123.jpg'') #将网页截图,保存到此目录
url = llqdx.current_url
print(url)
neir = llqdx.page_source #获取网页内容
print(neir)
llqdx.quit() #关闭浏览器
pat = "<title>(.*?)</title>"
title = re.compile(pat).findall(neir) #正则匹配网页标题
print(title)
【转载自:http://www.lqkweb.com】
centos 7安装phantomjs
centos 7安装phantomjs
wget https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-x86_64.tar.bz2
yum install bzip2 # 安装bzip2
tar -jxvf phantomjs-2.1.1-linux-x86_64.tar.bz2
mv phantomjs-2.1.1-linux-x86_64 /usr/local/src/phantomjs
ln -sf /usr/local/src/phantomjs/bin/phantomjs /usr/local/bin/phantomjs
yum install fontconfig freetype2
phantomjs -v # 测试版本号
安装中文字体
yum install bitmap-fonts bitmap-fonts-cjk
yum groupinstall "fonts" -y # 安装字体相关的依赖包
fc-cache # 刷新字体缓存
CentOS NodeJS PhantomJS PhearJS 失败的尝试……
Install GCC 4.8+
PhearJS 需要 C11 的支持,而 CentOS 6 目前最新的 gcc 不支持。所以需要自己编译安装 gcc 。这里以 gcc 4.9.4 为例,下载链接以中科大镜像为例:
$ cd ~ $ wget -c http://mirrors.ustc.edu.cn/gnu/gcc/gcc-4.9.4/gcc-4.9.4.tar.bz2 $ tar -jxvf gcc-4.9.4.tar.bz2 $ ./contrib/download_prerequisites $ cd .. $ mkdir gcc4.9.4-build $ cd gcc4.9.4-build $ ../gcc-4.9.4/configure --enable-checking=release --enable-languages=c,c++ --disable-multilib $ make -j4 $ sudo make install
安装完成后,可以查看 gcc 的版本:
$ gcc --version gcc (GCC) 4.9.4 copyright (C) 2015 Free Software Foundation,Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or fitness FOR A PARTIculaR PURPOSE.
Install Binutils
在 configure glibc 2.24 的过程中,会提示 as ld 版本过低,所以要首先升级 binutils 。
$ cd ~ $ wget -c http://mirrors.ustc.edu.cn/gnu/binutils/binutils-2.27.tar.gz $ tar zxvf binutils-2.27.tar.gz $ mkdir binutils2.27-build && cd binutils2.27-build $ ../binutils-2.27/configure $ make -j4 $ make install
Install GLIBC
$ wget -c http://mirrors.ustc.edu.cn/gnu/glibc/glibc-2.24.tar.gz $ tar zxvf glibc-2.24.tar.gz $ mkdir glibc2.24-build && cd glibc2.24-build $ ../glibc-2.24/configure $
configure 的过程提示:
configure: error: *** These critical programs are missing or too old: as ld *** Check the INSTALL file for required versions.
似乎要先把 binutils 也更新了……
然而,在更新了 binutils 之后,又遇到了 linux kernel header files missing or too old! 的问题……感觉还是换服务器比较合适……之前在 Archlinux 上运行 PhearJS 成功过。
checking installed Linux kernel header files... missing or too old! configure: error: GNU libc requires kernel header files from Linux 3.2.0 or later to be installed before configuring. The kernel header files are found usually in /usr/include/asm and /usr/include/linux; make sure these directories use files from Linux 3.2.0 or later. This check uses <linux/version.h>,so make sure that file was built correctly when installing the kernel header files. To use kernel headers not from /usr/include/linux,use the configure option --with-headers.
Install NodeJS
通过源码编译安装的方法:
$ wget -c https://nodejs.org/dist/v6.9.1/node-v6.9.1.tar.gz $ tar zxvf node-v6.9.1.tar.gz $ cd node-v6.9.1 $ ./configure $ make -j4 $ sudo make install
Install PhantomJS
PhantomJS 的安装比较简单,直接从 PhantomJS 官网下载 binary package ,解压,放入路径中就可以了。本文以 PhantomJS 2.1.1 为例
$ sudo yum install fontconfig $ cd ~ $ wget -c https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-x86_64.tar.bz2 $ tar -jxvf phantomjs-2.1.1-linux-x86_64.tar.bz2 $ mv phantomjs-2.1.1-linux-x86_64 phantomjs
向 ~/.bashrc 中添加如下的内容:
export PATH=$HOME/phantomjs/bin:$PATH
Install memcached
$ sudo yum install memcached
Install PhearJS
$ cd ~ $ git clone https://github.com/Tomtomgo/phearjs.git $ cd ~/phearjs $ npm install
如果觉得 npm 太慢,国内的玩家可以考虑阿里巴巴的淘宝 NPM 镜像: https://npm.taobao.org/
先用以下命令安装 cnpm :
$ sudo npm install -g cnpm --registry=https://registry.npm.taobao.org
然后用 cnpm install
替换 npm install
。
java.lang.IllegalStateException:该驱动程序不可执行:/resources/phantomjs-2.1.1-linux-x86_64/bin/phantomjs
我正在尝试在Jenkins(Unix)中以无头模式运行Selenium UI测试。我在Unix环境中使用了正确的phantomJS版本。
phantomjs-2.1.1-linux-x86_64/bin/phantomjs
我收到上述错误。有见识吗?如果需要,我将提供更多详细信息。
java.lang.IllegalStateException: The driver is not executable: /resources/phantomjs-2.1.1-linux-x86_64/bin/phantomjs
我们今天的关于PhantomJS:管道输入和管道输入是什么的分享就到这里,谢谢您的阅读,如果想了解更多关于16、web爬虫讲解2—PhantomJS虚拟浏览器+selenium模块操作PhantomJS、centos 7安装phantomjs、CentOS NodeJS PhantomJS PhearJS 失败的尝试……、java.lang.IllegalStateException:该驱动程序不可执行:/resources/phantomjs-2.1.1-linux-x86_64/bin/phantomjs的相关信息,可以在本站进行搜索。
本文标签: