していること
Python
+Bottle
+Selenium
+PhantomJS
でGoogle検索をします。
phantomjs
はapp.py
と同じディレクトリにあります。
ローカルではエラーは出ないのですが、Herokuに上げるとエラーを吐きます。
トレースバックを見ていただければわかると思うのですが、タイミングはdriverを作っている
driver = webdriver.PhantomJS(desired_capabilities=des_cap, executable_path="./phantomjs")
ここのようです。
ちょっと原因がさっぱりなのでこまっています。
以下にエラーが出た際のログがあります。
Python
python
1# app.py 2 3import os 4from bottle import route, run, request 5from bs4 import BeautifulSoup 6from bottle import TEMPLATE_PATH, jinja2_template as template 7from urllib.request import urlopen 8from urllib.parse import quote_plus, quote 9from selenium import webdriver 10from selenium.webdriver.common.desired_capabilities import DesiredCapabilities 11 12TEMPLATE_PATH.append("./templates") 13 14@route('/') 15def index(): 16 return template('index.html') 17 18@route('/result', method="POST") 19def result(): 20 keyword = request.forms.getunicode("keyword") 21 print(keyword.encode("utf-8").decode("utf-8")) 22 urls = google_search_result(keyword) 23 return template('result.html', urls=urls, keyword=keyword) 24 25def create_driver(): 26 des_cap = dict(DesiredCapabilities.PHANTOMJS) 27 des_cap["phantomjs.page.settings.userAgent"] = ( 28 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) ' 29 'Chrome/28.0.1500.52 Safari/537.36' 30 ) 31 driver = webdriver.PhantomJS(desired_capabilities=des_cap, executable_path="./phantomjs") 32 return driver 33 34def google_search_result(search_keyword): 35 urls = [] 36 parsed_keyword = quote_plus(search_keyword, encoding="utf-8") 37 driver = create_driver() 38 driver.get("https://www.google.co.jp/search?q=" + 39 parsed_keyword + "&num=100") 40 html = driver.page_source.encode('utf-8') 41 soup = BeautifulSoup(html, 'lxml') 42 sts = soup.find_all("h3", class_="r") 43 driver.close() 44 for st in sts: 45 urls.append(st.a["href"]) 46 return urls 47 48 49run(host="0.0.0.0", port=int(os.environ.get("PORT", 5000))) 50
heroku logs
2017-07-20T02:07:24.819491+00:00 app[web.1]: Traceback (most recent call last): 2017-07-20T02:07:24.819493+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/bottle.py", line 862, in _handle 2017-07-20T02:07:24.819494+00:00 app[web.1]: return route.call(**args) 2017-07-20T02:07:24.819494+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/bottle.py", line 1740, in wrapper 2017-07-20T02:07:24.819495+00:00 app[web.1]: rv = callback(*a, **ka) 2017-07-20T02:07:24.819496+00:00 app[web.1]: File "app.py", line 20, in result 2017-07-20T02:07:24.819496+00:00 app[web.1]: urls = google_search_result(keyword) 2017-07-20T02:07:24.819497+00:00 app[web.1]: File "app.py", line 35, in google_search_result 2017-07-20T02:07:24.819497+00:00 app[web.1]: driver = create_driver() 2017-07-20T02:07:24.819498+00:00 app[web.1]: File "app.py", line 29, in create_driver 2017-07-20T02:07:24.819499+00:00 app[web.1]: driver = webdriver.PhantomJS(desired_capabilities=des_cap, executable_path="./phantomjs") 2017-07-20T02:07:24.819500+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/selenium/webdriver/phantomjs/webdriver.py", line 52, in __init__ 2017-07-20T02:07:24.819500+00:00 app[web.1]: self.service.start() 2017-07-20T02:07:24.819501+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/selenium/webdriver/common/service.py", line 74, in start 2017-07-20T02:07:24.819501+00:00 app[web.1]: stdout=self.log_file, stderr=self.log_file) 2017-07-20T02:07:24.819502+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/subprocess.py", line 707, in __init__ 2017-07-20T02:07:24.819503+00:00 app[web.1]: restore_signals, start_new_session) 2017-07-20T02:07:24.819503+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/subprocess.py", line 1333, in _execute_child 2017-07-20T02:07:24.819504+00:00 app[web.1]: raise child_exception_type(errno_num, err_msg) 2017-07-20T02:07:24.819505+00:00 app[web.1]: OSError: [Errno 8] Exec format error
解決策がありましたらご教示いただけると幸いです。よろしくお願いいたします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/07/20 04:29
2017/07/20 04:45