-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_ra_dec.py
30 lines (24 loc) · 971 Bytes
/
get_ra_dec.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
from bs4 import BeautifulSoup
from selenium import webdriver
import time
def get_ra_dec(driver, query):
url = f'http://ned.ipac.caltech.edu/byname?objname={query}&hconst=67.8&omegam=0.308&omegav=0.692&wmap=4&corr_z=1'
driver.get(url)
time.sleep(10)
html = driver.page_source
soup = BeautifulSoup(html, 'html.parser')
ra = dec = mag = None
coord_row = soup.find('tr', {'class': 'ov_insiderow ov_inside_coord_row'})
if coord_row:
ra_span = coord_row.find('span', {'id': 'allbyname_7'})
dec_span = coord_row.find('span', {'id': 'allbyname_8'})
if ra_span:
ra = ra_span.text.strip()
if dec_span:
dec = dec_span.text.strip()
mag_row = soup.find('tr', {'class': 'ov_insiderow ov_inside_photom_row_3'})
if mag_row:
mag_span = mag_row.find('span', {'id': 'allbyname_53'})
if mag_span:
mag = mag_span.text.strip().split()[0]
return ra, dec, mag