1

I'm trying to use python webdriver to get html source in linux.

But I got below error:

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!

Can someone help me?

version: python -> 2.7.9 This is my code.

#-*- 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()
Usman Maqbool
  • 3,351
  • 10
  • 31
  • 48
jonggu
  • 146
  • 1
  • 2
  • 10

1 Answers1

2

In your code Change line

xephyr=Display(visible=1, size=(320, 240)).start()

to

xephyr=Display(visible=0, size=(320, 240)).start()  # visible=0

If backend Xephyr::

display = Display(visible=1, size=(320, 240)).start()  # visible=1

if backend Xvfb:

display = Display(visible=0, size=(320, 240)).start()  # visible=0
Ravi Kumar
  • 1,769
  • 2
  • 21
  • 31
  • Thankx!! but, i got another err msg like that selenium.common.exceptions.WebDriverException: Message: Service /usr/local/bin/chromedriver unexpectedly exited. Status code was: 1 – jonggu Jun 22 '16 at 08:41
  • above code will work for firefox webdriver. this [link](http://stackoverflow.com/questions/8255929/running-webdriver-chrome-with-selenium/24364290#24364290) will helps for WebDriverException in chrome webdriver – Ravi Kumar Jun 22 '16 at 08:46