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

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

新規登録して質問してみよう
ただいま回答率
85.48%
Windows 10

Windows 10は、マイクロソフト社がリリースしたOSです。Modern UIを標準画面にした8.1から、10では再びデスクトップ主体に戻され、UIも変更されています。PCやスマホ、タブレットなど様々なデバイスに幅広く対応していることが特徴です。

PowerShell

Windows PowerShellはコマンドラインインターフェースであり、システム管理を含むWindowsタスク自動化のためのスクリプト言語です。

Python

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

selenium

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

Q&A

0回答

3534閲覧

このエラーはどうゆう意味でしょうか。

Kokku

総合スコア39

Windows 10

Windows 10は、マイクロソフト社がリリースしたOSです。Modern UIを標準画面にした8.1から、10では再びデスクトップ主体に戻され、UIも変更されています。PCやスマホ、タブレットなど様々なデバイスに幅広く対応していることが特徴です。

PowerShell

Windows PowerShellはコマンドラインインターフェースであり、システム管理を含むWindowsタスク自動化のためのスクリプト言語です。

Python

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

selenium

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

0グッド

1クリップ

投稿2020/03/28 03:42

開発環境
python3.8
windows10
powershell

python

1#coding:utf-8 2import time 3import getpass 4import requests 5import json 6from selenium.webdriver.support.ui import Select 7from selenium import webdriver 8from selenium.webdriver.chrome.options import Options 9from webdriver_manager.chrome import ChromeDriverManager 10# --headlessだけではOSによって動かない、プロキシが弾かれる、 11# CUI用の省略されたHTMLが帰ってくるなどの障害が出ます。 12# 長いですが、これら6行あって最強かつどんな環境でも動きますので、必ず抜かさないようにしてください。 13# 仮想ブラウザ起動、URL先のサイトにアクセス 14#driver = webdriver.Chrome(ChromeDriverManager().install()) 15#browser = webdriver.Chrome() 16#driver.get("http://2captcha.com/in.php?key=") 17#driver = webdriver.Chrome() 18#driver.get('https://www.google.com/') 19chrome_options = webdriver.ChromeOptions() 20chrome_options.add_experimental_option("excludeSwitches", ['enable-automation']) 21driver = webdriver.Chrome(ChromeDriverManager().install(), options=chrome_options) 22driver.get("http://2captcha.com/in.php?key=") 23 24 25chrome_options.add_argument("--disable-gpu"); 26chrome_options.add_argument("--disable-infobars") 27chrome_options.add_argument("--disable-extensions"); 28chrome_options.add_argument("--proxy-server='direct://'"); 29chrome_options.add_argument("--proxy-bypass-list=*"); 30chrome_options.add_argument("--start-maximized"); 31chrome_options.add_argument("--headless"); 32driver = webdriver.Chrome(ChromeDriverManager().install(), options=chrome_options) 33# JSでtextareaタグのdisplay:noneを削除する 34driver = webdriver.Chrome(ChromeDriverManager().install(), options=chrome_options) 35driver.execute_script('var element=document.getElementById("g-recaptcha-response"); element.style.display="";') 36 37service_key = 'a658155478a999c6f853060fbb573865' # 2captcha service key 38google_site_key = '6Ld2sf4SAAAAAKSgzs0Q13IZhY02Pyo31S2jgOB5' # reCAPTCHAのdata-sitekey 39pageurl = 'https://patrickhlauke.github.io/recaptcha/' 40url = "http://2captcha.com/in.php?key=" + service_key + "&method=userrecaptcha&googlekey=" + google_site_key + "&pageurl=" + pageurl 41 42resp = requests.get(url) 43if resp.text[0:2] != 'OK': 44 quit('Service error. Error code:' + resp.text) 45captcha_id = resp.text[3:] 46 47fetch_url = "http://2captcha.com/res.php?key="+ service_key + "&action=get&id=" + captcha_id 48 49for i in range(1, 10): 50 time.sleep(5) # wait 5 sec. 51 resp = requests.get(fetch_url) 52 if resp.text[0:2] == 'OK': 53 break 54print('Google response token: ', resp.text[3:]) 55# textareaにトークンを入力する 56driver.find_element_by_id('g-recaptcha-response').send_keys(resp.text[3:]) 57#表示したサイトのスクリーンショットを撮る 58#browser.save_screenshot('screen.png') 59 60#表示した瞬間消えちゃうから幅を持たせておく 61time.sleep(5) 62 63# サイト内から検索フォームを探す。 64# Googleでは検索フォームのNameが「q」です。 65#el = driver.find_element_by_name("q") 66# 検索フォームに文字を入力 67#el.send_keys('supreme.com') 68#time.sleep(2) 69 70# 検索フォーム送信(Enter) 71#el.submit() 72 73#from bs4 import BeautifulSoup 74#soup = BeautifulSoup(driver.page_source, features="html.parser") 75# タイトルをターミナル上に表示 76#print(soup.title.string) 77

pythonでreCAPTCHAのチェックボックスの突破できるコード作りに今取り組んでいます。
仮想環境を作りそこでファイルを実行させようとしているのですが、なかなか」作ることができません。

(pycharm) PS C:\Users\shota\documents\selenium\bot\pycharm> python selenium_sample4.py Trying to download new driver from http://chromedriver.storage.googleapis.com/80.0.3987.106/chromedriver_win32.zip Unpack archive C:\Users\shota.wdm\drivers\chromedriver\80.0.3987.106\win32\chromedriver.zip DevTools listening on ws://127.0.0.1:54857/devtools/browser/2523f511-ba22-4d05-88f1-9d9a7757a034 Looking for [chromedriver 80.0.3987.106 win32] driver in cache File found in cache by path [C:\Users\shota.wdm\drivers\chromedriver\80.0.3987.106\win32\chromedriver.exe] DevTools listening on ws://127.0.0.1:54875/devtools/browser/eb816b8d-3420-4836-bf6e-8f5e1d8e7b26 Looking for [chromedriver 80.0.3987.106 win32] driver in cache File found in cache by path [C:\Users\shota.wdm\drivers\chromedriver\80.0.3987.106\win32\chromedriver.exe] DevTools listening on ws://127.0.0.1:54890/devtools/browser/8255db34-ca8a-4d63-8bc3-dcb671da93e4 Traceback (most recent call last): File "selenium_sample4.py", line 35, in <module> driver.execute_script('var element=document.getElementById("g-recaptcha-response"); element.style.display="";') File "C:\Users\shota\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 634, in execute_script return self.execute(command, { File "C:\Users\shota\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute self.error_handler.check_response(response) File "C:\Users\shota\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.JavascriptException: Message: javascript error: Cannot read property 'style' of null (Session info: headless chrome=80.0.3987.149) Exception ignored in: <function Popen.__del__ at 0x033A7DF0> Traceback (most recent call last): File "C:\Users\shota\AppData\Local\Programs\Python\Python38-32\lib\subprocess.py", line 945, in __del__ self._internal_poll(_deadstate=_maxsize) File "C:\Users\shota\AppData\Local\Programs\Python\Python38-32\lib\subprocess.py", line 1344, in _internal_poll if _WaitForSingleObject(self._handle, 0) == _WAIT_OBJECT_0: OSError: [WinError 6] ハンドルが無効です。 (pycharm) PS C:\Users\shota\documents\selenium\bot\pycharm> python selenium_sample4.py Looking for [chromedriver 80.0.3987.106 win32] driver in cache File found in cache by path [C:\Users\shota.wdm\drivers\chromedriver\80.0.3987.106\win32\chromedriver.exe] DevTools listening on ws://127.0.0.1:54911/devtools/browser/a6125727-c9a1-4216-ba41-b7c111242bea Looking for [chromedriver 80.0.3987.106 win32] driver in cache File found in cache by path [C:\Users\shota.wdm\drivers\chromedriver\80.0.3987.106\win32\chromedriver.exe] DevTools listening on ws://127.0.0.1:54929/devtools/browser/6d6ab102-3002-46b7-8d04-cad0497c88e7 Looking for [chromedriver 80.0.3987.106 win32] driver in cache File found in cache by path [C:\Users\shota.wdm\drivers\chromedriver\80.0.3987.106\win32\chromedriver.exe] DevTools listening on ws://127.0.0.1:54947/devtools/browser/11e31c4f-ee2b-4d9f-8b45-fdd023947c52 Traceback (most recent call last): File "selenium_sample4.py", line 35, in <module> driver.execute_script('var element=document.getElementById("g-recaptcha-response"); element.style.display="";') File "C:\Users\shota\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 634, in execute_script return self.execute(command, { File "C:\Users\shota\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute self.error_handler.check_response(response) File "C:\Users\shota\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.JavascriptException: Message: javascript error: Cannot read property 'style' of null (Session info: headless chrome=80.0.3987.149) (pycharm) PS C:\Users\shota\documents\selenium\bot\pycharm>

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

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

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

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

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

guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

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

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

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問