2017-08-09 163 views
0

我创建了一个使用Selenium webdriver删除网站的python脚本。现在我试图使用CGI从Web运行此脚本。 因此,为了确保我的CGI服务器工作我尝试这样做:从Python CGI脚本运行Selenium webdriver

import cgi 
print 'Content-Type: text/html' 
print 
list_brand = ['VOLVO','FIAT', 'BMW'] 
print '<h1>TESTING CGI</h1>' 
print '<form>' 
print '<select>' 
for i in range(3): 
     print '<option value="' + list_brand[i] + '">'+ list_brand[i] +'</option>' 
print '</select>' 
print '</form>' 

它工作得很好。现在,当我用CGI使用Selenium时,使用以下脚本:

import cgitb 
import cgi 
from selenium import webdriver 

print 'Content-Type: text/html' 
print 
cgitb.enable(display=0, logdir="C:/path/to/log/directory") 
path_to_pjs = 'C:path/to/phantomjs-2.1.1-windows/bin/phantomjs.exe' 
browser = webdriver.PhantomJS(executable_path = path_to_pjs) 
#Reaching to URL 
url = 'http://www.website.fr/cl/2/products' 
browser.get(url) 
div_set = browser.find_elements_by_class_name('productname') 
print '<form>' 
print '<select>' 
for div in div_set: 
     print '<option value="' + div.find_element_vy_tag_name('h3').text + '">'+ div.find_element_vy_tag_name('h3').text +'</option>' 
print '</select>' 
print '</form>' 

页面不断加载但不响应。任何想法,如果这是可能的(我的意思是从CGI脚本运行硒)或为什么我的服务器不响应?

回答

0

嗯,我找到了我的问题的解决方案!第一:我没有注意到我在我的功能中写了vy而不是bydiv.find_element_by_tag_name。 第二件事是使用Apache服务器。由于某些原因,使用CGIHTTPServer的lite python服务器不起作用。因此,我使用XAMPP修改了httpd.conf文件,最后一项是将脚本#!/Python27/python添加到脚本中。