2012-02-09 2 views
0

last question에 RSS 피드의 XML 링크를 구문 분석하는 데 도움을 요청했습니다. 나는 다른 질문에서 언급 한 바와 같이파이썬 출력에서 ​​한 줄 가져 오기

def GetRSS(RSSurl): 
    url_info = urllib.urlopen(RSSurl) 
    if (url_info): 
     xmldoc = minidom.parse(url_info) 
    if (xmldoc): 
     channel = xmldoc.getElementsByTagName('channel') 
     for node in channel: 
      item = xmldoc.getElementsByTagName('item') 
      for node in item: 
       alist = xmldoc.getElementsByTagName('link') 
       for a in alist: 
        linktext = a.firstChild.data 
        print linktext 

, 내가 RSS feed on Redlettermedia.com에서 링크를 얻는 쓴 : 여기 추가 연구와 함께 지원에서받은 아이디어를 사용하여, 나는이 쓸 수 있었다. 코드는 정상적으로 작동하고 수신 출력은 다음과 같습니다.

http://redlettermedia.com 
http://redlettermedia.com/half-in-the-bag-b-fest-2012/ 
http://redlettermedia.com/an-update-from-red-letter-media/ 
http://redlettermedia.com/half-in-the-bag-red-tails/ 
http://redlettermedia.com/half-in-the-bag-the-devil-inside-and-flyin-ryan/ 
http://redlettermedia.com/newly-found-episode-iii-review-behind-the-scenes-footage/ 
http://redlettermedia.com/half-in-the-bag-the-girl-with-the-dragon-tattoo-and-2011-re-cap/ 
http://redlettermedia.com/mr-plinetts-indiana-jones-and-the-kingdom-of-the-crystal-skull-review/ 
http://redlettermedia.com/new-mr-plinkett-review-trailer/ 
http://redlettermedia.com/plinkett-fest/ 
http://redlettermedia.com/update/ 
http://redlettermedia.com 
http://redlettermedia.com/half-in-the-bag-b-fest-2012/ 
http://redlettermedia.com/an-update-from-red-letter-media/ 
http://redlettermedia.com/half-in-the-bag-red-tails/ 
http://redlettermedia.com/half-in-the-bag-the-devil-inside-and-flyin-ryan/ 
http://redlettermedia.com/newly-found-episode-iii-review-behind-the-scenes-footage/ 

등등. 내가 지금하고 싶은 것은 함수 (이 경우 출력의 두 번째 줄 "http://redlettermedia.com/half-in-the-bag-b-fest-2012/")에 대한 결과로 최신 업데이트 링크 만 인쇄하는 것입니다. 해당 줄만 어떻게 인쇄합니까?

+0

당신이 아닌 다음 stdlib 모듈을 설치할 수 있습니다 시도 할 수 목록에서 두 번째 항목 있다면? '최신 업데이트 링크'를 어떻게 정의합니까? – Daenyth

답변

1

항상 당신이

url = xmldoc.getElementsByTagName('link')[1].firstChild.data 
print url 
+0

이것은 나가 얻는 것을 시도하고 있던 URL를 반복하는 10의 선을 받는다는 것을 제외하면 거의 완벽하게 작동한다. 내가 원했던 URL을 수신하는 것과는 대조적으로, 나는 그것을하기 위해 무엇을하고 있습니까? – Jordan

+0

목록에있는 모든 항목에 대해 인쇄하기 때문입니다. 당신은 대체로 'item in node :'이후의 것을 대체 할 것이지만, 나는 그 순간에 테스트 할 수 없다 ... – timc

+0

글쎄, 나는 그것이 내가해야할 일이라고 생각했다. 나는'item in node :'에 대한 모든 것을 당신이 제안한 것으로 완전히 대체했지만, 나는 여전히 어떤 이유로 10 개의 라인을 얻는 것처럼 보입니다. – Jordan