运行 来自 Python CGI 脚本的 Selenium webdriver
Running Selenium webdriver from a Python CGI script
我创建了一个 python 脚本,它使用 Selenium webdriver 来废弃网站。现在,我正在尝试使用 CGI 从 Web 运行 此脚本。
因此,为了确保我的 CGI 服务器正常工作,我尝试了这个:
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>'
而且效果很好。现在,当我使用此脚本将 Selenium 与 CGI 结合使用时:
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>'
页面一直在加载但没有响应。知道这是否可能(我的意思是 运行ning 来自 cgi 脚本的 selenium)或者为什么我的服务器没有响应?
好吧,我找到了解决问题的方法!其一:我没有注意到我在我的函数中写了 vy
而不是 by
:div.find_element_by_tag_name
。
第二件事是使用 Apache 服务器。出于某种原因,使用 CGIHTTPServer 的精简版 python 服务器无法正常工作。所以我使用 XAMPP 修改了 httpd.conf
文件,最后一件事是将路径 #!/Python27/python
添加到脚本中。
我创建了一个 python 脚本,它使用 Selenium webdriver 来废弃网站。现在,我正在尝试使用 CGI 从 Web 运行 此脚本。 因此,为了确保我的 CGI 服务器正常工作,我尝试了这个:
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>'
而且效果很好。现在,当我使用此脚本将 Selenium 与 CGI 结合使用时:
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>'
页面一直在加载但没有响应。知道这是否可能(我的意思是 运行ning 来自 cgi 脚本的 selenium)或者为什么我的服务器没有响应?
好吧,我找到了解决问题的方法!其一:我没有注意到我在我的函数中写了 vy
而不是 by
:div.find_element_by_tag_name
。
第二件事是使用 Apache 服务器。出于某种原因,使用 CGIHTTPServer 的精简版 python 服务器无法正常工作。所以我使用 XAMPP 修改了 httpd.conf
文件,最后一件事是将路径 #!/Python27/python
添加到脚本中。