터미널 ubuntu python error : [Errno 8] Exec format error 해결하는 방법이 어떻게 되나요?
조회수 1277회
파이썬 2.7쓰고있구요 아래 함수를 로컬에서 실행시키면 정상 실행 됩니다. 그런데 ubuntu 서버에 접속해서 터미널에서 직접 돌리면 [Errno 8] Exec format error가 뜹니다
코드는 아래와 같습니다.
# -*- coding: utf-8 -*-
from selenium import webdriver
import time
from bs4 import BeautifulSoup as bs
from datetime import datetime, timedelta
import json
from selenium.webdriver.common.keys import Keys
import requests
import random
import sys
import math
reload(sys)
sys.setdefaultencoding('utf8')
url='http://www.sohu.com/c/18/774?spm=smpc.auto-home.side-nav.14.1570682908136xGf0TUa'
driver=None
date_now=str(datetime.now())
month=date_now.split("-")[1]
day=date_now.split("-")[2].split(" ")[0]
hour=date_now.split(" ")[1].split(":")[0]
if int(day)>=10:
day='0{}'.format(int(day)-2)
else:
day='{}'.format(int(day)-2)
break_time=unicode('{}-{} {}'.format(month,day,hour))
try:
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('user-agent=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36')
chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('disable-gpu')
chrome_options.add_argument('--disable-dev-shm-usage')
driver = webdriver.Chrome(executable_path='/home/ubuntu/chromedriver',chrome_options=chrome_options)
# driver = webdriver.Chrome(executable_path='/Applications/chromedriver',chrome_options=chrome_options)
driver.get(url)
time.sleep(4)
last_height=driver.execute_script('return document.body.scrollHeight')
num=1
while True:
driver.execute_script('window.scrollTo(0, document.body.scrollHeight);')
time.sleep(3)
psc=driver.page_source
bs4=bs(psc, ('html.parser'))
news_items=bs4.findAll('div',{'data-role':'news-item'})
news_url_list=list()
for news in news_items:
news_url=news.find('h4').find('a').get('href').replace("//","")
news_time=news.find('span',{'class':'time'}).text
print news_url
news_url_list.append(news_url)
# print '스크롤 {}번 / '.format(num),unicode(news_time.split(":")[0]) , break_time, '/ 뉴스 url 수: ',len(news_items)
# print unicode(news_time.split(":")[0].split(" ")[0]) , unicode(break_time.split(" ")[0]) , int(news_time.split(":")[0].split(" ")[1]) , int(break_time.split(" ")[1])
# print unicode(news_time.split(":")[0].split(" ")[0]) == unicode(break_time.split(" ")[0]), int(news_time.split(":")[0].split(" ")[1]) < int(break_time.split(" ")[1])
if unicode(news_time.split(":")[0].split(" ")[0]) == unicode(break_time.split(" ")[0]) and int(news_time.split(":")[0].split(" ")[1]) < int(break_time.split(" ")[1]):
break
num+=1
print '수집 뉴스 : ',len(news_url_list),'개'
except Exception as e:
print e
finally:
if driver is not None:
driver.quit()
sys.exit()
1 답변
-
- 제가 이미 봤었던 내용인데 #! .envs/mts/bin/python이렇게 했는데 똑같은 에러가 발생하는데 문제가 뭘까요? 김재민 2019.10.10 16:47
- 풀패쓰여야 하지 않을까요? https://stackoverflow.com/questions/44076804/what-shebang-to-use-for-python-scripts-run-under-a-pyenv-virtualenv 이걸 보면, `#!/usr/bin/env python` 도 해보세요. nowp 2019.10.10 17:43
- 해봤지만 여전히 안 되네요..ㅜㅜ 김재민 2019.10.10 17:50
댓글 입력