質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
Beautiful Soup

Beautiful Soupは、Pythonのライブラリの一つ。スクレイピングに特化しています。HTMLデータの構文の解析を行うために、HTMLタグ/CSSのセレクタで抽出する部分を指定することが可能です。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

selenium

Selenium(セレニウム)は、ブラウザをプログラムで作動させるフレームワークです。この原理を使うことにより、ブラウザのユーザーテストなどを自動化にすることができます。

Q&A

0回答

1639閲覧

python seleniumがGCP環境でうまく起動しない

tonytony

総合スコア11

Beautiful Soup

Beautiful Soupは、Pythonのライブラリの一つ。スクレイピングに特化しています。HTMLデータの構文の解析を行うために、HTMLタグ/CSSのセレクタで抽出する部分を指定することが可能です。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

selenium

Selenium(セレニウム)は、ブラウザをプログラムで作動させるフレームワークです。この原理を使うことにより、ブラウザのユーザーテストなどを自動化にすることができます。

0グッド

0クリップ

投稿2020/08/25 22:18

現状
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

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

FiroProchainezo

2020/08/26 02:26

GCPで使っているサービス名(Compute Engineかな?)と、OS(WindowsとかLinuxとか)を教えてください。
tonytony

2020/08/26 04:45

ご連絡いただきありがとうございます! GCPの、Cloud Functionsを使っています。 OSはmacOSのMojaveの10.14.6になります!
FiroProchainezo

2020/08/26 05:19

このあたりが参考になりそうです。 https://qiita.com/NearMugi/items/8146306168dd6b41b217 実行環境は質問を編集して追記してください。 また、クラウドが絡むと複雑になりがちですので、環境を書く場合は「開発環境」と「クラウド」を別々に詳細を記載ください。 クラウドの質問なのに使用サービスを記載していないのは「回答を求めていない質問」に見えてしまいます。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問