質問編集履歴

3

追記

2020/03/25 15:35

投稿

Kokku
Kokku

スコア39

test CHANGED
File without changes
test CHANGED
@@ -1,3 +1,5 @@
1
+ --------------------------------------------------------
2
+
1
3
  ```#coding:utf-8
2
4
 
3
5
  import time
@@ -152,11 +154,19 @@
152
154
 
153
155
 
154
156
 
157
+ ```
158
+
159
+
160
+
161
+ ------------------------------------------------------
162
+
163
+
164
+
155
165
 
156
166
 
157
167
  python モジュールについて
158
168
 
159
- ![イメージ説明](cbec92c5ffaf173993473ad7f34b78b0.png)
169
+
160
170
 
161
171
 
162
172
 
@@ -196,7 +206,11 @@
196
206
 
197
207
  エラー内容
198
208
 
209
+
210
+
211
+ ------------------------------------------------------------
212
+
199
- python selenium_sample4.py
213
+ ```python selenium_sample4.py
200
214
 
201
215
 
202
216
 
@@ -215,3 +229,7 @@
215
229
  op = chrome_options()
216
230
 
217
231
  TypeError: 'Options' object is not callable
232
+
233
+ ```
234
+
235
+ -----------------------------------------------------------

2

追記

2020/03/25 15:35

投稿

Kokku
Kokku

スコア39

test CHANGED
File without changes
test CHANGED
@@ -1,3 +1,159 @@
1
+ ```#coding:utf-8
2
+
3
+ import time
4
+
5
+ import getpass
6
+
7
+ import requests
8
+
9
+ import json
10
+
11
+ from selenium.webdriver.support.ui import Select
12
+
13
+ from selenium import webdriver
14
+
15
+ from selenium.webdriver.chrome.options import Options
16
+
17
+ from webdriver_manager.chrome import ChromeDriverManager
18
+
19
+ # --headlessだけではOSによって動かない、プロキシが弾かれる、
20
+
21
+ # CUI用の省略されたHTMLが帰ってくるなどの障害が出ます。
22
+
23
+ # 長いですが、これら6行あって最強かつどんな環境でも動きますので、必ず抜かさないようにしてください。
24
+
25
+ # 仮想ブラウザ起動、URL先のサイトにアクセス
26
+
27
+ #driver = webdriver.Chrome(ChromeDriverManager().install())
28
+
29
+ #browser = webdriver.Chrome()
30
+
31
+ #driver.get("http://2captcha.com/in.php?key=")
32
+
33
+ #driver = webdriver.Chrome()
34
+
35
+ #driver.get('https://www.google.com/')
36
+
37
+ chrome_options = webdriver.ChromeOptions()
38
+
39
+ chrome_options.add_experimental_option("excludeSwitches", ['enable-automation'])
40
+
41
+ driver = webdriver.Chrome(ChromeDriverManager().install(), options=chrome_options)
42
+
43
+ driver.get("http://2captcha.com/in.php?key=")
44
+
45
+
46
+
47
+ op = chrome_options()
48
+
49
+ op.add_argument("--disable-gpu");
50
+
51
+ op.add_argument("--disable-infobars")
52
+
53
+ op.add_argument("--disable-extensions");
54
+
55
+ op.add_argument("--proxy-server='direct://'");
56
+
57
+ op.add_argument("--proxy-bypass-list=*");
58
+
59
+ op.add_argument("--start-maximized");
60
+
61
+ op.add_argument("--headless");
62
+
63
+ driver = webdriver.Chrome(ChromeDriverManager().install(), options=chrome_options)
64
+
65
+ # JSでtextareaタグのdisplay:noneを削除する
66
+
67
+ driver = webdriver.Chrome(ChromeDriverManager().install(), options=chrome_options)
68
+
69
+ driver.execute_script('var element=document.getElementById("g-recaptcha-response"); element.style.display="";')
70
+
71
+
72
+
73
+ service_key = 'a658155478a999c6f853060fbb573865' # 2captcha service key
74
+
75
+ google_site_key = '6Ld2sf4SAAAAAKSgzs0Q13IZhY02Pyo31S2jgOB5' # reCAPTCHAのdata-sitekey
76
+
77
+ pageurl = 'https://patrickhlauke.github.io/recaptcha/'
78
+
79
+ url = "http://2captcha.com/in.php?key=" + service_key + "&method=userrecaptcha&googlekey=" + google_site_key + "&pageurl=" + pageurl
80
+
81
+
82
+
83
+ resp = requests.get(url)
84
+
85
+ if resp.text[0:2] != 'OK':
86
+
87
+ quit('Service error. Error code:' + resp.text)
88
+
89
+ captcha_id = resp.text[3:]
90
+
91
+
92
+
93
+ fetch_url = "http://2captcha.com/res.php?key="+ service_key + "&action=get&id=" + captcha_id
94
+
95
+
96
+
97
+ for i in range(1, 10):
98
+
99
+ time.sleep(5) # wait 5 sec.
100
+
101
+ resp = requests.get(fetch_url)
102
+
103
+ if resp.text[0:2] == 'OK':
104
+
105
+ break
106
+
107
+ print('Google response token: ', resp.text[3:])
108
+
109
+ # textareaにトークンを入力する
110
+
111
+ driver.find_element_by_id('g-recaptcha-response').send_keys(resp.text[3:])
112
+
113
+ #表示したサイトのスクリーンショットを撮る
114
+
115
+ #browser.save_screenshot('screen.png')
116
+
117
+
118
+
119
+ #表示した瞬間消えちゃうから幅を持たせておく
120
+
121
+ time.sleep(5)
122
+
123
+
124
+
125
+ # サイト内から検索フォームを探す。
126
+
127
+ # Googleでは検索フォームのNameが「q」です。
128
+
129
+ #el = driver.find_element_by_name("q")
130
+
131
+ # 検索フォームに文字を入力
132
+
133
+ #el.send_keys('supreme.com')
134
+
135
+ #time.sleep(2)
136
+
137
+
138
+
139
+ # 検索フォーム送信(Enter)
140
+
141
+ #el.submit()
142
+
143
+
144
+
145
+ #from bs4 import BeautifulSoup
146
+
147
+ #soup = BeautifulSoup(driver.page_source, features="html.parser")
148
+
149
+ # タイトルをターミナル上に表示
150
+
151
+ #print(soup.title.string)
152
+
153
+
154
+
155
+
156
+
1
157
  python モジュールについて
2
158
 
3
159
  ![イメージ説明](cbec92c5ffaf173993473ad7f34b78b0.png)
@@ -36,162 +192,6 @@
36
192
 
37
193
 
38
194
 
39
- コード
40
-
41
-
42
-
43
- #coding:utf-8
44
-
45
- import time
46
-
47
- import getpass
48
-
49
- import requests
50
-
51
- import json
52
-
53
- from selenium.webdriver.support.ui import Select
54
-
55
- from selenium import webdriver
56
-
57
- from selenium.webdriver.chrome.options import Options
58
-
59
- from webdriver_manager.chrome import ChromeDriverManager
60
-
61
- # --headlessだけではOSによって動かない、プロキシが弾かれる、
62
-
63
- # CUI用の省略されたHTMLが帰ってくるなどの障害が出ます。
64
-
65
- # 長いですが、これら6行あって最強かつどんな環境でも動きますので、必ず抜かさないようにしてください。
66
-
67
- # 仮想ブラウザ起動、URL先のサイトにアクセス
68
-
69
- #driver = webdriver.Chrome(ChromeDriverManager().install())
70
-
71
- #browser = webdriver.Chrome()
72
-
73
- #driver.get("http://2captcha.com/in.php?key=")
74
-
75
- #driver = webdriver.Chrome()
76
-
77
- #driver.get('https://www.google.com/')
78
-
79
- chrome_options = webdriver.ChromeOptions()
80
-
81
- chrome_options.add_experimental_option("excludeSwitches", ['enable-automation'])
82
-
83
- driver = webdriver.Chrome(ChromeDriverManager().install(), options=chrome_options)
84
-
85
- driver.get("http://2captcha.com/in.php?key=")
86
-
87
-
88
-
89
- op = chrome_options()
90
-
91
- op.add_argument("--disable-gpu");
92
-
93
- op.add_argument("--disable-infobars")
94
-
95
- op.add_argument("--disable-extensions");
96
-
97
- op.add_argument("--proxy-server='direct://'");
98
-
99
- op.add_argument("--proxy-bypass-list=*");
100
-
101
- op.add_argument("--start-maximized");
102
-
103
- op.add_argument("--headless");
104
-
105
- driver = webdriver.Chrome(ChromeDriverManager().install(), options=chrome_options)
106
-
107
- # JSでtextareaタグのdisplay:noneを削除する
108
-
109
- driver = webdriver.Chrome(ChromeDriverManager().install(), options=chrome_options)
110
-
111
- driver.execute_script('var element=document.getElementById("g-recaptcha-response"); element.style.display="";')
112
-
113
-
114
-
115
- service_key = 'a658155478a999c6f853060fbb573865' # 2captcha service key
116
-
117
- google_site_key = '6Ld2sf4SAAAAAKSgzs0Q13IZhY02Pyo31S2jgOB5' # reCAPTCHAのdata-sitekey
118
-
119
- pageurl = 'https://patrickhlauke.github.io/recaptcha/'
120
-
121
- url = "http://2captcha.com/in.php?key=" + service_key + "&method=userrecaptcha&googlekey=" + google_site_key + "&pageurl=" + pageurl
122
-
123
-
124
-
125
- resp = requests.get(url)
126
-
127
- if resp.text[0:2] != 'OK':
128
-
129
- quit('Service error. Error code:' + resp.text)
130
-
131
- captcha_id = resp.text[3:]
132
-
133
-
134
-
135
- fetch_url = "http://2captcha.com/res.php?key="+ service_key + "&action=get&id=" + captcha_id
136
-
137
-
138
-
139
- for i in range(1, 10):
140
-
141
- time.sleep(5) # wait 5 sec.
142
-
143
- resp = requests.get(fetch_url)
144
-
145
- if resp.text[0:2] == 'OK':
146
-
147
- break
148
-
149
- print('Google response token: ', resp.text[3:])
150
-
151
- # textareaにトークンを入力する
152
-
153
- driver.find_element_by_id('g-recaptcha-response').send_keys(resp.text[3:])
154
-
155
- #表示したサイトのスクリーンショットを撮る
156
-
157
- #browser.save_screenshot('screen.png')
158
-
159
-
160
-
161
- #表示した瞬間消えちゃうから幅を持たせておく
162
-
163
- time.sleep(5)
164
-
165
-
166
-
167
- # サイト内から検索フォームを探す。
168
-
169
- # Googleでは検索フォームのNameが「q」です。
170
-
171
- #el = driver.find_element_by_name("q")
172
-
173
- # 検索フォームに文字を入力
174
-
175
- #el.send_keys('supreme.com')
176
-
177
- #time.sleep(2)
178
-
179
-
180
-
181
- # 検索フォーム送信(Enter)
182
-
183
- #el.submit()
184
-
185
-
186
-
187
- #from bs4 import BeautifulSoup
188
-
189
- #soup = BeautifulSoup(driver.page_source, features="html.parser")
190
-
191
- # タイトルをターミナル上に表示
192
-
193
- #print(soup.title.string)
194
-
195
195
 
196
196
 
197
197
  エラー内容

1

追記

2020/03/25 15:22

投稿

Kokku
Kokku

スコア39

test CHANGED
File without changes
test CHANGED
@@ -33,3 +33,185 @@
33
33
 
34
34
 
35
35
  いろいろページからコードを拾ってきてくっつけているのでこれはpython3.8にはないモジュールだということでしょうか。このエラーの原因は何なんでしょうか。
36
+
37
+
38
+
39
+ コード
40
+
41
+
42
+
43
+ #coding:utf-8
44
+
45
+ import time
46
+
47
+ import getpass
48
+
49
+ import requests
50
+
51
+ import json
52
+
53
+ from selenium.webdriver.support.ui import Select
54
+
55
+ from selenium import webdriver
56
+
57
+ from selenium.webdriver.chrome.options import Options
58
+
59
+ from webdriver_manager.chrome import ChromeDriverManager
60
+
61
+ # --headlessだけではOSによって動かない、プロキシが弾かれる、
62
+
63
+ # CUI用の省略されたHTMLが帰ってくるなどの障害が出ます。
64
+
65
+ # 長いですが、これら6行あって最強かつどんな環境でも動きますので、必ず抜かさないようにしてください。
66
+
67
+ # 仮想ブラウザ起動、URL先のサイトにアクセス
68
+
69
+ #driver = webdriver.Chrome(ChromeDriverManager().install())
70
+
71
+ #browser = webdriver.Chrome()
72
+
73
+ #driver.get("http://2captcha.com/in.php?key=")
74
+
75
+ #driver = webdriver.Chrome()
76
+
77
+ #driver.get('https://www.google.com/')
78
+
79
+ chrome_options = webdriver.ChromeOptions()
80
+
81
+ chrome_options.add_experimental_option("excludeSwitches", ['enable-automation'])
82
+
83
+ driver = webdriver.Chrome(ChromeDriverManager().install(), options=chrome_options)
84
+
85
+ driver.get("http://2captcha.com/in.php?key=")
86
+
87
+
88
+
89
+ op = chrome_options()
90
+
91
+ op.add_argument("--disable-gpu");
92
+
93
+ op.add_argument("--disable-infobars")
94
+
95
+ op.add_argument("--disable-extensions");
96
+
97
+ op.add_argument("--proxy-server='direct://'");
98
+
99
+ op.add_argument("--proxy-bypass-list=*");
100
+
101
+ op.add_argument("--start-maximized");
102
+
103
+ op.add_argument("--headless");
104
+
105
+ driver = webdriver.Chrome(ChromeDriverManager().install(), options=chrome_options)
106
+
107
+ # JSでtextareaタグのdisplay:noneを削除する
108
+
109
+ driver = webdriver.Chrome(ChromeDriverManager().install(), options=chrome_options)
110
+
111
+ driver.execute_script('var element=document.getElementById("g-recaptcha-response"); element.style.display="";')
112
+
113
+
114
+
115
+ service_key = 'a658155478a999c6f853060fbb573865' # 2captcha service key
116
+
117
+ google_site_key = '6Ld2sf4SAAAAAKSgzs0Q13IZhY02Pyo31S2jgOB5' # reCAPTCHAのdata-sitekey
118
+
119
+ pageurl = 'https://patrickhlauke.github.io/recaptcha/'
120
+
121
+ url = "http://2captcha.com/in.php?key=" + service_key + "&method=userrecaptcha&googlekey=" + google_site_key + "&pageurl=" + pageurl
122
+
123
+
124
+
125
+ resp = requests.get(url)
126
+
127
+ if resp.text[0:2] != 'OK':
128
+
129
+ quit('Service error. Error code:' + resp.text)
130
+
131
+ captcha_id = resp.text[3:]
132
+
133
+
134
+
135
+ fetch_url = "http://2captcha.com/res.php?key="+ service_key + "&action=get&id=" + captcha_id
136
+
137
+
138
+
139
+ for i in range(1, 10):
140
+
141
+ time.sleep(5) # wait 5 sec.
142
+
143
+ resp = requests.get(fetch_url)
144
+
145
+ if resp.text[0:2] == 'OK':
146
+
147
+ break
148
+
149
+ print('Google response token: ', resp.text[3:])
150
+
151
+ # textareaにトークンを入力する
152
+
153
+ driver.find_element_by_id('g-recaptcha-response').send_keys(resp.text[3:])
154
+
155
+ #表示したサイトのスクリーンショットを撮る
156
+
157
+ #browser.save_screenshot('screen.png')
158
+
159
+
160
+
161
+ #表示した瞬間消えちゃうから幅を持たせておく
162
+
163
+ time.sleep(5)
164
+
165
+
166
+
167
+ # サイト内から検索フォームを探す。
168
+
169
+ # Googleでは検索フォームのNameが「q」です。
170
+
171
+ #el = driver.find_element_by_name("q")
172
+
173
+ # 検索フォームに文字を入力
174
+
175
+ #el.send_keys('supreme.com')
176
+
177
+ #time.sleep(2)
178
+
179
+
180
+
181
+ # 検索フォーム送信(Enter)
182
+
183
+ #el.submit()
184
+
185
+
186
+
187
+ #from bs4 import BeautifulSoup
188
+
189
+ #soup = BeautifulSoup(driver.page_source, features="html.parser")
190
+
191
+ # タイトルをターミナル上に表示
192
+
193
+ #print(soup.title.string)
194
+
195
+
196
+
197
+ エラー内容
198
+
199
+ python selenium_sample4.py
200
+
201
+
202
+
203
+ Looking for [chromedriver 80.0.3987.106 win32] driver in cache
204
+
205
+ File found in cache by path [C:\Users\shota.wdm\drivers\chromedriver\80.0.3987.106\win32\chromedriver.exe]
206
+
207
+
208
+
209
+ DevTools listening on ws://127.0.0.1:52954/devtools/browser/75118533-cf06-4f96-bc41-8d0402ab89af
210
+
211
+ Traceback (most recent call last):
212
+
213
+ File "selenium_sample4.py", line 24, in <module>
214
+
215
+ op = chrome_options()
216
+
217
+ TypeError: 'Options' object is not callable