【发布时间】:2018-08-04 02:52:26
【问题描述】:
我正在尝试从this website 中提取第一个 ISS TLE(两线元素集)。
我需要以下前三行:
TWO LINE MEAN ELEMENT SET
文本:(ISS 行,1 行,2 行)。
所以我用漂亮的汤得到了我想要的文本,但是我真的不知道如何提取这些文本行。我不能使用split(),因为我需要准确地维护这三行中的空白。如何做到这一点?
import urllib2
from bs4 import BeautifulSoup
import ephem
import datetime
nasaissurl = 'http://spaceflight.nasa.gov/realdata/sightings/SSapplications/Post/JavaSSOP/orbit/ISS/SVPOST.html'
soup = BeautifulSoup(urllib2.urlopen(nasaissurl), 'html.parser')
body = soup.find_all("pre")
index = 0
firstTLE = False
for tag in body:
if "ISS" in tag.text:
print tag.text
【问题讨论】:
标签: python string python-2.7 beautifulsoup