My cleanup code works fine on my local computer (Windows 8), but it doesn't work on the Digital Ocean camera (Ubuntu 16.04). It always fails in the second cycle, giving Bad Status Line or URLError .. We have already spent several hours searching Google for a problem ...
Setup:
PhantomJS 2.1.1
Selenium 2.53.6
Python 2.7
class Elitebet: t1 = time.time() driver = webdriver.PhantomJS() def controller(self): self.driver.get("http://www.elitebetkenya.com/coupon.php?d") element = WebDriverWait(self.driver, 10).until( EC.presence_of_element_located((By.ID, "page"))) soup = BeautifulSoup(self.driver.page_source.encode('utf-8'),"html.parser") page_number = self.number_of_pages(soup) self.eliteparser(soup) for i in range(0, page_number - 10): page_click = self.driver.find_element_by_xpath("//input[@value='Next']") page_click.click() element = WebDriverWait(self.driver, 10).until( EC.presence_of_element_located((By.ID, "page"))) time.sleep(randint(1,2)) soup = BeautifulSoup(self.driver.page_source.encode('utf-8'),"html.parser") self.eliteparser(soup) t2 = time.time() - self.t1 print t2 def number_of_pages(self, x): numbers = x.find("div", {"class" : "pgLnx"}).contents[2] return int(re.findall(r'\d+', numbers)[0]) def eliteparser(self,x): tbody = x.find("tbody")
The error message is as follows:
File "elitebet.py", line 147, in <module> elite.controller() File "elitebet.py", line 45, in controller page_click.click() File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webelement.py", line 72, in click self._execute(Command.CLICK_ELEMENT) File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webelement.py", line 461, in _execute return self._parent.execute(command, params) File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 234, in execute response = self.command_executor.execute(driver_command, params) File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/remote_connection.py", line 401, in execute return self._request(command_info[0], url, body=data) File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/remote_connection.py", line 471, in _request resp = opener.open(request, timeout=self._timeout) File "/usr/lib/python2.7/urllib2.py", line 429, in open response = self._open(req, data) File "/usr/lib/python2.7/urllib2.py", line 447, in _open '_open', req) File "/usr/lib/python2.7/urllib2.py", line 407, in _call_chain result = func(*args) File "/usr/lib/python2.7/urllib2.py", line 1228, in http_open return self.do_open(httplib.HTTPConnection, req) File "/usr/lib/python2.7/urllib2.py", line 1198, in do_open raise URLError(err) urllib2.URLError: <urlopen error [Errno 111] Connection refused>