-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchatter-sample.py
36 lines (31 loc) · 1.21 KB
/
chatter-sample.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# simple chatter!
# do read the readme, it explains a lot of what you'll need and what's going on here
# imports
from selenium import webdriver
from selenium.webdriver.support.wait import WebDriverWait as wait
from selenium.webdriver.support.expected_conditions import visibility_of_element_located as appeared
from selenium.webdriver.firefox.options import Options
# headless firefox
oppy=Options()
oppy.add_argument('-headless')
browser=webdriver.Firefox(options=oppy)
browser.get('https://you.com/?chatMode=default')
query_number=0
# query, answer fetch, and self-delete
def query(message):
global query_number
browser.find_element('xpath','//*[@id="search-input-textarea"]').send_keys(message+"\ue006")
query_number+=1
def answer():
p = f"/html/body/div/div/div/div[1]/div/div[2]/div/div[1]/div/div[1]/div/div[{2*query_number}]/div/div[2]"
pb = r"/html/body/div/div/div/div[1]/div/div[2]/div/div[1]/div/div[2]/div[1]/button"
wait(browser,10).until(appeared(['xpath',pb]))
wait(browser,60).until_not(appeared(['xpath',pb]))
return browser.find_element('xpath',p).text
def __del__():
browser.quit()
# looooop
while True:
query(input('::: '))
print(f'--> {answer()}')
# TODO develop tkinter ui