質問編集履歴
1
コードの追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -4,16 +4,190 @@
|
|
4
4
|
|
5
5
|
にアクセスすると、まず番号のcaptchaが出てきます。
|
6
6
|
|
7
|
-
|
7
|
+
これは画像認識で突破しましたが、次にアルファベットで読みづらそうなcaptchaが出てきます。
|
8
8
|
|
9
9
|
|
10
10
|
|
11
|
+
画像認識は複雑で無理でした。
|
12
|
+
|
11
|
-
|
13
|
+
音声認識は、スピーカーから流れる音をマイクで拾って音声を読み取って入力しても、
|
14
|
+
|
15
|
+
正確にアルファベットを聞き取ることができないようです。
|
12
16
|
|
13
17
|
|
14
18
|
|
15
|
-
を
|
19
|
+
どなたかお力を貸していただけないでしょうか。
|
16
20
|
|
17
21
|
|
18
22
|
|
23
|
+
```python
|
24
|
+
|
25
|
+
rom selenium import webdriver
|
26
|
+
|
27
|
+
from selenium.webdriver.common.keys import Keys
|
28
|
+
|
29
|
+
from bs4 import BeautifulSoup
|
30
|
+
|
31
|
+
import requests
|
32
|
+
|
33
|
+
import pandas as pd
|
34
|
+
|
35
|
+
import csv
|
36
|
+
|
37
|
+
import time
|
38
|
+
|
39
|
+
import urllib.parse
|
40
|
+
|
41
|
+
import re
|
42
|
+
|
43
|
+
import numpy as np
|
44
|
+
|
45
|
+
from selenium.webdriver.common.by import By
|
46
|
+
|
47
|
+
from selenium.webdriver.common.action_chains import ActionChains
|
48
|
+
|
49
|
+
from selenium.webdriver.chrome.options import Options
|
50
|
+
|
51
|
+
from selenium.common.exceptions import NoSuchElementException
|
52
|
+
|
53
|
+
from selenium.common.exceptions import ElementNotInteractableException
|
54
|
+
|
55
|
+
from PIL import Image, ImageTk, ImageGrab
|
56
|
+
|
57
|
+
import pytesseract
|
58
|
+
|
59
|
+
import cv2
|
60
|
+
|
61
|
+
import matplotlib.pyplot as plt
|
62
|
+
|
63
|
+
from PIL import Image
|
64
|
+
|
65
|
+
import speech_recognition as sr
|
66
|
+
|
67
|
+
from selenium.webdriver.support.ui import WebDriverWait
|
68
|
+
|
69
|
+
from selenium.webdriver.support import expected_conditions as EC
|
70
|
+
|
71
|
+
import sounddevice as sd
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
browser = webdriver.Chrome()
|
80
|
+
|
81
|
+
browser.maximize_window()
|
82
|
+
|
83
|
+
url= "https://www.uen.gov.sg/"
|
84
|
+
|
85
|
+
browser.get(url)
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
# full screen
|
92
|
+
|
93
|
+
#ImageGrab.grab().save("PIL_capture.png")
|
94
|
+
|
95
|
+
# 指定した領域内をクリッピング
|
96
|
+
|
97
|
+
ImageGrab.grab(bbox=(700, 800, 1150, 1050)).save("PIL_capture_clip.png")
|
98
|
+
|
99
|
+
#bbox=(左, 上, 右, 下)
|
100
|
+
|
101
|
+
img = Image.open("PIL_capture_clip.png")
|
102
|
+
|
103
|
+
#img.show() # 画像表示
|
104
|
+
|
105
|
+
time.sleep(1)
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
num = pytesseract.image_to_string(img, config = "--psm 7 nobatch digits")
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
print(num)
|
114
|
+
|
115
|
+
time.sleep(3)
|
116
|
+
|
117
|
+
WebDriverWait(browser,15).until(EC.presence_of_element_located((By.XPATH, "//*[@id='input1']")))
|
118
|
+
|
119
|
+
userNameField = browser.find_element_by_xpath("//*[@id='input1']")
|
120
|
+
|
121
|
+
userNameField.send_keys(int(num))
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
WebDriverWait(browser,15).until(EC.presence_of_element_located((By.XPATH, "//*[@id='Button1']")))
|
126
|
+
|
127
|
+
submitButton = browser.find_element_by_xpath("//*[@id='Button1']")
|
128
|
+
|
19
|
-
|
129
|
+
submitButton.click()
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
time.sleep(0.5)
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
WebDriverWait(browser,15).until(EC.presence_of_element_located((By.XPATH, "//*[@id='pt1:r1:0:r1:0:cb21']")))
|
138
|
+
|
139
|
+
submitButton = browser.find_element_by_xpath("//*[@id='pt1:r1:0:r1:0:cb21']")
|
140
|
+
|
141
|
+
submitButton.click()
|
142
|
+
|
143
|
+
|
144
|
+
|
145
|
+
#0 Built-in Microphone, Core Audio (2 in, 0 out)
|
146
|
+
|
147
|
+
#1 Built-in Output, Core Audio (0 in, 2 out)
|
148
|
+
|
149
|
+
|
150
|
+
|
151
|
+
r = sr.Recognizer()
|
152
|
+
|
153
|
+
mic = sr.Microphone()
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
with mic as source:
|
158
|
+
|
159
|
+
r.adjust_for_ambient_noise(source)
|
160
|
+
|
161
|
+
audio = r.listen(source)
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
#print(r.recognize_google(audio,language = 'eg-US'))
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
audio = r.recognize_google(audio, language='eg-US')
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
#print(type(audio))
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
code = browser.find_element_by_xpath("//*[@id='pt1:r1:0:r1:0:it1::content']")
|
178
|
+
|
179
|
+
code.send_keys(audio)
|
180
|
+
|
181
|
+
print(audio)
|
182
|
+
|
183
|
+
|
184
|
+
|
185
|
+
time.sleep(4)
|
186
|
+
|
187
|
+
submitButton = browser.find_element_by_xpath("//*[@id='pt1:r1:0:cb11::icon']")
|
188
|
+
|
189
|
+
submitButton.click()
|
190
|
+
|
191
|
+
|
192
|
+
|
193
|
+
```
|