質問編集履歴
1
コードの追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,10 +1,97 @@
|
|
1
1
|
https://www.uen.gov.sg/
|
2
2
|
|
3
3
|
にアクセスすると、まず番号のcaptchaが出てきます。
|
4
|
-
|
4
|
+
これは画像認識で突破しましたが、次にアルファベットで読みづらそうなcaptchaが出てきます。
|
5
5
|
|
6
|
+
画像認識は複雑で無理でした。
|
6
|
-
|
7
|
+
音声認識は、スピーカーから流れる音をマイクで拾って音声を読み取って入力しても、
|
8
|
+
正確にアルファベットを聞き取ることができないようです。
|
7
9
|
|
8
|
-
を
|
10
|
+
どなたかお力を貸していただけないでしょうか。
|
9
11
|
|
12
|
+
```python
|
13
|
+
rom selenium import webdriver
|
14
|
+
from selenium.webdriver.common.keys import Keys
|
15
|
+
from bs4 import BeautifulSoup
|
16
|
+
import requests
|
17
|
+
import pandas as pd
|
18
|
+
import csv
|
19
|
+
import time
|
20
|
+
import urllib.parse
|
21
|
+
import re
|
22
|
+
import numpy as np
|
23
|
+
from selenium.webdriver.common.by import By
|
24
|
+
from selenium.webdriver.common.action_chains import ActionChains
|
25
|
+
from selenium.webdriver.chrome.options import Options
|
26
|
+
from selenium.common.exceptions import NoSuchElementException
|
27
|
+
from selenium.common.exceptions import ElementNotInteractableException
|
28
|
+
from PIL import Image, ImageTk, ImageGrab
|
29
|
+
import pytesseract
|
30
|
+
import cv2
|
31
|
+
import matplotlib.pyplot as plt
|
32
|
+
from PIL import Image
|
33
|
+
import speech_recognition as sr
|
34
|
+
from selenium.webdriver.support.ui import WebDriverWait
|
35
|
+
from selenium.webdriver.support import expected_conditions as EC
|
36
|
+
import sounddevice as sd
|
37
|
+
|
38
|
+
|
39
|
+
|
40
|
+
browser = webdriver.Chrome()
|
41
|
+
browser.maximize_window()
|
42
|
+
url= "https://www.uen.gov.sg/"
|
43
|
+
browser.get(url)
|
44
|
+
|
45
|
+
|
46
|
+
# full screen
|
47
|
+
#ImageGrab.grab().save("PIL_capture.png")
|
48
|
+
# 指定した領域内をクリッピング
|
49
|
+
ImageGrab.grab(bbox=(700, 800, 1150, 1050)).save("PIL_capture_clip.png")
|
50
|
+
#bbox=(左, 上, 右, 下)
|
51
|
+
img = Image.open("PIL_capture_clip.png")
|
52
|
+
#img.show() # 画像表示
|
53
|
+
time.sleep(1)
|
54
|
+
|
55
|
+
num = pytesseract.image_to_string(img, config = "--psm 7 nobatch digits")
|
56
|
+
|
57
|
+
print(num)
|
58
|
+
time.sleep(3)
|
59
|
+
WebDriverWait(browser,15).until(EC.presence_of_element_located((By.XPATH, "//*[@id='input1']")))
|
60
|
+
userNameField = browser.find_element_by_xpath("//*[@id='input1']")
|
61
|
+
userNameField.send_keys(int(num))
|
62
|
+
|
63
|
+
WebDriverWait(browser,15).until(EC.presence_of_element_located((By.XPATH, "//*[@id='Button1']")))
|
64
|
+
submitButton = browser.find_element_by_xpath("//*[@id='Button1']")
|
10
|
-
|
65
|
+
submitButton.click()
|
66
|
+
|
67
|
+
time.sleep(0.5)
|
68
|
+
|
69
|
+
WebDriverWait(browser,15).until(EC.presence_of_element_located((By.XPATH, "//*[@id='pt1:r1:0:r1:0:cb21']")))
|
70
|
+
submitButton = browser.find_element_by_xpath("//*[@id='pt1:r1:0:r1:0:cb21']")
|
71
|
+
submitButton.click()
|
72
|
+
|
73
|
+
#0 Built-in Microphone, Core Audio (2 in, 0 out)
|
74
|
+
#1 Built-in Output, Core Audio (0 in, 2 out)
|
75
|
+
|
76
|
+
r = sr.Recognizer()
|
77
|
+
mic = sr.Microphone()
|
78
|
+
|
79
|
+
with mic as source:
|
80
|
+
r.adjust_for_ambient_noise(source)
|
81
|
+
audio = r.listen(source)
|
82
|
+
|
83
|
+
#print(r.recognize_google(audio,language = 'eg-US'))
|
84
|
+
|
85
|
+
audio = r.recognize_google(audio, language='eg-US')
|
86
|
+
|
87
|
+
#print(type(audio))
|
88
|
+
|
89
|
+
code = browser.find_element_by_xpath("//*[@id='pt1:r1:0:r1:0:it1::content']")
|
90
|
+
code.send_keys(audio)
|
91
|
+
print(audio)
|
92
|
+
|
93
|
+
time.sleep(4)
|
94
|
+
submitButton = browser.find_element_by_xpath("//*[@id='pt1:r1:0:cb11::icon']")
|
95
|
+
submitButton.click()
|
96
|
+
|
97
|
+
```
|