-
Notifications
You must be signed in to change notification settings - Fork 0
/
parser.py
87 lines (65 loc) · 3.33 KB
/
parser.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from inconsistencyFixer import fix_str
import time
#Ground constants
delay = 2
d_angle = '140s' #s
def search_question(name, RAh, RAm, RAs, DE, DEd, DEm, DEs, Epoch):
if str(RAh) in [str(i) for i in range(10)]:
RAh = '0' + str(RAh)
if str(RAm) in [str(i) for i in range(10)]:
RAm = '0' + str(RAm)
if str(DEd) in [str(i) for i in range(10)]:
DEd = '0' + str(DEd)
if str(DEm) in [str(i) for i in range(10)]:
DEm = '0' + str(DEm)
return '{0} {1} {2} {3} {4}{5} {6} {7} {8}'.format(name, RAh, RAm, RAs, DE, DEd, DEm, DEs, Epoch)
class Searcher():
def __init__(self) -> None:
self.driver = webdriver.Chrome()
def search(self, name, RAh, RAm, RAs, DE, DEd, DEm, DEs, Epoch, save_adress = '', *tags):
probably_tags = ['All', 'Radio', 'Infra Red', 'Selected', 'Objects', 'X-Ray']
links = ['cats_match_all',
'r_cats_match_sel',
'ir_cats_match_sel',
'cats_match_sel',
'o_cats_match_sel',
'x_cats_match_sel'
]
url = 'https://www.sao.ru/cats/'
suffix = '.html'
for tag in tags:
if tag in probably_tags:
self.driver.get(url + links[probably_tags.index(tag)] + suffix)
#elems = self.driver.find_element(by=By.CSS_SELECTOR, value ='a')
#elems.find_element(by=By., value=)
#to select all possible sets
all_on = self.driver.find_element(by=By.XPATH, value = '//a[@href="{0}"]'.format(links[probably_tags.index(tag)] + '_a' + suffix))
all_on.click()
#to set off few sets due to a need of search
if tag == 'Radio':
RFC = self.driver.find_element(by=By.XPATH, value = '//input[@value="RFC"]')
RFC.click()
ICRF = self.driver.find_element(by=By.XPATH, value = '//input[@value="ICRF"]')
ICRF.click()
#time.sleep(delay)
#setup the search
input_angle = self.driver.find_element(by=By.XPATH, value = '//input[@name="X_RADIUS"]')
input_angle.clear()
input_angle.send_keys(d_angle)
epoch = self.driver.find_element(by=By.XPATH, value = '//input[@name="EPOCH"]')
epoch.clear()
epoch.send_keys(Epoch)
textarea = self.driver.find_element(by=By.XPATH, value = '//textarea[@name="LIST_OBJ"]')
textarea.send_keys(search_question(name, RAh, RAm, RAs, DE, DEd, DEm, DEs, Epoch))
#time.sleep(5)
submit = self.driver.find_element(by=By.XPATH, value = '//input[@type="SUBMIT"]')
submit.click()
download = self.driver.find_element(by=By.XPATH, value = '//a[contains(.,"Here are search results")]')
download.click()
with open('{0}{1}.txt'.format(save_adress, name), 'w') as f:
f.write(fix_str(self.driver.find_element(by=By.TAG_NAME, value = "body").text))
#time.sleep(delay * 200)
#self.driver.close()