我试图使用python webdriver在linux中获取html源代码。
但是我得到了以下错误:
python daiwa.py 'http://asp.hotel-story.ne.jp/ver3d/planlist.asp?herehcod1=DWHQ0&sAreacode=00151&hidmode=select&mode=seek&hidSELECTARRYMD=2016/06/22&hidSELECTadult=1'Traceback (most recent call last):
File "/var/www/daiwa/lib/otas/daiwa.py", line 9, in <module>
xephyr=Display(visible=1, size=(320, 240)).start()
File "/usr/local/lib/python2.7/site-packages/pyvirtualdisplay/display.py", line 33, in __init__self._obj = self.display_class(
File "/usr/local/lib/python2.7/site-packages/pyvirtualdisplay/display.py", line 51, in display_classcls.check_installed()
File "/usr/local/lib/python2.7/site-packages/pyvirtualdisplay/xephyr.py", line 30, in check_installed ubuntu_package=PACKAGE).check_installed()
File "/usr/local/lib/python2.7/site-packages/easyprocess/__init__.py", line 180, in check_installed
raise EasyProcessCheckInstalledError(self)
easyprocess.EasyProcessCheckInstalledError: cmd=['Xephyr', '-help']
OSError=[Errno 2] No such file or directory
Program install error!
有人可以帮助我吗?
版本:python - &gt; 2.7.9 这是我的代码。
#-*- coding: utf-8 -*-
from pyvirtualdisplay import Display
from selenium import webdriver
xephyr=Display(visible=1, size=(320, 240)).start()
path_to_chromedriver = "/usr/local/bin/chromedriver"
templete = webdriver.Chrome("/usr/local/bin/chromedriver")
templete.get("https://asp.hotel-story.ne.jp/ver3d/planlist.asp?hcod1=DWHQ0&hcod2=001&hidmode=select&mode=seek&hidSELECTARRYMD=2016/6/25&hidSELECTHAKSU=1&room=1&hidSELECTadult=1&hidSELECTchilda=0&hidSELECTchildb=0&hidSELECTchildc=0&hidSELECTchildd=0&hidSELECTminPrice=0&hidSELECTmaxPrice=9999999&Dispunit=&chkymd=0&chkpsn=0&sAreacode=00101")
templete.find_element_by_xpath("//select[@id='seekCount']/option[@value='9999']").click()
html_source = templete.page_source
if isinstance(html_source, unicode):
html_source = html_source.encode('UTF-8')
print html_source
templete.close()
答案 0 :(得分:1)
在您的代码更改行
中xephyr=Display(visible=1, size=(320, 240)).start()
到
xephyr=Display(visible=0, size=(320, 240)).start() # visible=0
如果后端 Xephyr::
display = Display(visible=1, size=(320, 240)).start() # visible=1
如果后端 Xvfb:
display = Display(visible=0, size=(320, 240)).start() # visible=0