Por que meu rastreador executa o resultado diferente no Ubuntu Server?

3

Estou escrevendo alguns códigos para obter as URLs da janela do controle deslizante de imagens da página inicial do yahoo, que é incorporada por meio do javascript; portanto, uso o Selenium para simular uma ação de clique humano. A ilustração de código e detalhes está anexada ao arquivo python. Por favor me ajude a descobrir isso.

'''Since Ubuntu do not have physical FireFox Browser, so I use
xvfbwrapper to create the environment,
I only add it on the server site. Local testing, I did not add it. 
'''
#from xvfbwrapper import Xvfb
#with Xvfb() as xvfb:

from selenium import webdriver
import selenium.webdriver.support.ui as ui

url_path="https://sg.yahoo.com"
driver = webdriver.Firefox()
driver.get(url_path)
#wait until the Crawler find the Carousel-Ranges Class which is the image slider (it contains all the urls which i need)
first_result = ui.WebDriverWait(driver, 10).until(lambda driver: driver.find_element_by_class_name('Carousel-Ranges'))
#get the number of url to implement the for loop
imageRange = first_result.text
numString = imageRange.split("of ")
numInt = int(numString[1])
print numInt #print total number of URL that extracted through text

for x in range(0,((numInt-10)/5)+1):
    #simulate the click action. every single click, the javascript will enable 5 more urls so I can use "li.Cur-p a"
    #to get, and by default there are only 10 urls which are enabled.
    driver.find_element_by_css_selector("button[class*='End-0 T-0 B-0 Fz-30 Z-1']").click()
topNews = driver.find_elements_by_css_selector("li.Cur-p a");
#print out the urls list that cralwed. If it matches with previous number
# then it means I successfully get the result.
print len(topNews)

Mas este código só é viável para o teste local. Quando eu adiciono o xvfbwrapper e coloco no servidor, ele não funciona. Tomando um exemplo, se o total de URLs for 60, o rastreador será executado no local que retornou o mesmo resultado (60-sucesso); mas quando o servidor o executa, ele retorna apenas 10, o que é urls padrão. Portanto, deduzo que o problema pode causar por esse xvfbwrapper. Mas eu não sei como resolver isso. Alguém pode se dirigir sobre esse assunto? Obrigado novamente

    
por bobo123 23.11.2015 / 03:17

0 respostas

Tags