2017-08-09 1 views
0

Selenium webdriverを使用してWebサイトをスクラップする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

まあ、私の問題の解決策を見つけました! 1つ:私はの代わりにvyの代わりにdiv.find_element_by_tag_nameと書きました。 もう1つはApacheサーバーを使用していたことです。何らかの理由で、CGIHTTPServerを使用しているLite Pythonサーバーが動作しません。だから、XAMPPを使ってhttpd.confファイルを修正し、最後に#!/Python27/pythonというスクリプトをスクリプトに追加していました。

関連する問題