現状
GCPを用いてクラウドでスクレイピングを定期実行したいのですが、chromedriver.exeがうまく読み込めていないようで、エラーが出てしまいます。
GCSにexeファイルをアップロードし、適切なURIは取ってきていると思うですが、何が原因かわからず2日ほど悶々としている状況です。
少しでも何かわかりましたら教えていただけますと幸いです。
コード
python
1from selenium import webdriver 2from selenium.webdriver.common.by import By 3from selenium.webdriver.common.keys import Keys as keys 4from selenium.webdriver.support.ui import WebDriverWait 5import random 6import time 7import requests 8import pandas as pd 9from bs4 import BeautifulSoup 10import gspread 11from oauth2client.service_account import ServiceAccountCredentials 12 13def main(event, context): 14 # timetickeログイン情報 15 email = 'testtest' 16 passwords = 'testtest' 17 # ブラウザを開く 18 driver = webdriver.Chrome('gs://function-1-test/chromedriver.exe') 19 # webページを開く 20 driver.get('https://www.timeticket.jp/users/sign_in') 21 22 driver.implicitly_wait(2) 23 24 username = driver.find_element_by_css_selector("#user_email") 25 password = driver.find_element_by_css_selector("#user_password") 26 27 username.send_keys(email) 28 password.send_keys(passwords) 29 password.send_keys(keys.ENTER) 30 time.sleep(3) 31 32 url = "https://www.timeticket.jp/created_items" 33 driver.get(url) 34 time.sleep(3) 35 html = driver.page_source.encode('utf-8') 36 soup = BeautifulSoup(html, 'html.parser') 37 total_counts = soup.select_one('#wrapper > section > div > div > div:nth-of-type(3) > div > div > div > div > div:nth-of-type(1) > div.col-md-5 > div:nth-of-type(1) > span').text 38 total_solds = soup.select_one('#wrapper > section > div > div > div:nth-of-type(3) > div > div > div > div > div:nth-of-type(1) > div:nth-of-type(2) > div:nth-of-type(4) > span').text 39 40 time.sleep(3) 41 42 # scope = ["https://spreadsheets.google.com/feeds", 'https://www.googleapis.com/auth/spreadsheets', "https://www.googleapis.com/auth/drive.file",'https://www.googleapis.com/auth/drive'] 43 # 44 # creds = ServiceAccountCredentials.from_json_keyfile_name("creds.json", scope) 45 # 46 # client = gspread.authorize(creds) 47 # 48 # sheet = client.open("timeticket_KPI").developer 49 # 50 # data = sheet.get_all_records() 51 52 print(total_counts) 53 54 55 line_notify_token = 'testtest' 56 line_notify_api = 'https://notify-api.line.me/api/notify' 57 total_counts_message = '合計閲覧数は{}です\n'.format(total_counts) 58 total_solds_message = '合計購入数は{}\n'.format(total_solds) 59 notification_message = 'これはテスト版です。\n' + total_counts_message + total_solds_message 60 61 62 headers = {'Authorization': f'Bearer {line_notify_token}'} 63 data = {'message': f'message: {notification_message}'} 64 requests.post(line_notify_api, headers = headers, data = data) 65 66 67 68 driver.quit() 69 70
エラーメッセージ
Error: function terminated. Recommended action: inspect logs for termination reason. Details: Message: 'chromedriver.exe' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
あなたの回答
tips
プレビュー