Парсер плейлиста youtube не правильно срабатывает

Win 7. Python 2.7 GUI Парсер плейлиста youtube не правильно срабатывает. Запускается без ошибок. Ввожу первую ссылку в Python 2.7 GUI Создаётся файл data.txt Но этот файл пустой.

# coding: utf8
# == pars_playlist.py ==
# == select short information from Youtube playlist --
from urllib import urlopen
from BeautifulSoup import BeautifulSoup

print  "pars_playlist working..."

# == get first link of playlist  ==
url = raw_input('input link:')
#url = "https://www.youtube.com/watch?v=iEzTgqa0d3A&list=PLku9se_HAVOryGec5hev5TeD-eTSxv7z9&index=1"

fh = open('data.txt','w')  

cur_num = 1     # index of reading page 
try:
    while True:
        # -- get current page --
        print cur_num   
        print url
        content = urlopen( url )
        page = content.read()

        # -- cut head
        soup = BeautifulSoup(page)
        body = soup.find('body')

        # get current title
        span = body.find(id="eow-title")
        title = span.getText()
        print title
        
        # get list of all links
        ol = body.find(id="playlist-autoscroll-list")
        lis = ol.findAll('li')

        # seek for current page
        for idx, li in enumerate(lis): # seek for picture
            li_title = li["data-video-title"]
            if li_title == title:  break
        video_id = li["data-video-id"]

        # get picture inforation
        img = li.find('img')
        img_src = img['src']
        pos = img_src.find('?')
        if pos > 0: img_src = img_src[:pos]

        # get decription of page
        descr = body.find(id="eow-description")
        descr_text = descr.getText()
        
        # save information
        fh.write(title.encode('utf8') + '\n')
        fh.write(video_id.encode('utf8') + '\n')
        fh.write(img_src.encode('utf8') + '\n')
        fh.write(descr_text.encode('utf8') + '\n')
        fh.write('\n')

        if idx >= len(lis) -1:  break

        # get next url
        idx += 1
        li = lis[ idx ]
        anc = li.find( 'a' )
        href = anc['href']
        url="https://www.youtube.com" + href

        cur_num = cur_num + 1
# == 05 end of work ==
except:
    print "exception: ", cur_num
    pass
finally:
    fh.close()
    print "ok"
'''

Ответы (0 шт):