Beautifulsoup如何解析soup.find_all内容

时间:2017-01-18 18:33:43

标签: python beautifulsoup

soup.find_all已返回

[<span class="flight-number sp-g-tooltips" data-bundle2="Flight Details"  title="">5J  892</span>, <span class="flight-number sp-g-tooltips" data-bundle2="Flight Details" title="">5J  900</span>, <span class="flight-number sp-g-tooltips" data-bundle2="Flight Details" title="">5J  902</span>]
text1=soup.find_all("span", class_="flight-number sp-g-tooltips")

问题:如何解析内部文本,如5J892 5J900 5J902并存储在数组中?

1 个答案:

答案 0 :(得分:0)

text1=soup.find_all("span", class_="flight-number sp-g-tooltips")    
lines = [span.get_text() for span in text1]

列表理解将迭代text1中的每个范围并返回该范围的文本