import requests
import re
import time
from urllib import parse
def parser(datas):
for data in datas:
print(data)
def get_data(objid, keyword):
url = 'https://ned.ipac.caltech.edu/ffs/sticky/CmdSrv'
ff = str(int(time.time() * 1000))
data = {
'request': '{"startIdx":0,"pageSize":1000,"ffSessionId":"FF-Session-'+ff+'","filters":"","source":"http://ned.ipac.caltech.edu/cgi-bin/objsearch?extend=no&out_csys=Equatorial&out_equinox=J2000.0&obj_sort=RA+or+Longitude&of=xml_qlphot&zv_breaker=30000.0&list_limit=5&img_stamp=YES&objname='+keyword+'&hconst=67.8&omegam=0.308&omegav=0.692&wmap=4&corr_z=1&objid='+objid+'","alt_source":"http://ned.ipac.caltech.edu/cgi-bin/objsearch?extend=no&out_csys=Equatorial&out_equinox=J2000.0&obj_sort=RA+or+Longitude&of=xml_qlphot&zv_breaker=30000.0&list_limit=5&img_stamp=YES&objname='+keyword+'&hconst=67.8&omegam=0.308&omegav=0.692&wmap=4&corr_z=1&objid='+objid+'","META_INFO":{"title":"qlphot","tbl_id":"tbl_id-c50b9-6","col.Refcode.PrefWidth":"20","col.Spectral Region.PrefWidth":"14","col.Band.PrefWidth":"17","col.Apparent Mag or Flux.PrefWidth":"16","col.Reference code.PrefWidth":"12","selectInfo":"false--0"},"tbl_id":"tbl_id-c50b9-6","id":"IpacTableFromSource"}',
'cmd': 'tableSearch'
}
res = requests.post(url, headers=headers, data=data)
return res.json()['tableData']['data']
def get_objid(keyword):
url = f'https://ned.ipac.caltech.edu/byname?objname={keyword}&hconst=67.8&omegam=0.308&omegav=0.692&wmap=4&corr_z=1'
res = requests.get(url, headers=headers)
objid = re.findall('objid=(.*?)"', res.text)[0]
datas = get_data(objid, keyword)
parser(datas)
if __name__ == '__main__':
word = input('输入关键词:')
key_word = parse.quote(word)
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36'
}
get_objid(key_word)
|