python - Problems with navigablestrings and unicode in BeautifulSoup -


i having problems navigablestrings , unicode in beautifulsoup (python).

basically, parsing 4 results pages youtube, , putting top result's extension (end of url after youtube.com/watch?=) list.

i loop list in 2 other functions, on one, throws error: typeerror: 'navigablestring' object not callable. however, other 1 says typeerror: 'unicode' object not callable. both using same exact string.

what doing wrong here? know parsing code not perfect, i'm using both beautifulsoup , regex. in past whenever navigablestring errors, have thrown in ".encode('ascii', 'ignore') or str(), , has seemed work. appreciated!

    url in urls:         response = urllib2.urlopen(url)         html = response.read()         soup = beautifulsoup(html)         link_data = soup.findall("a", {"class":"yt-uix-tile-link result-item-translation-title"})[0]         ext = re.findall('href="/(.*)">', str(link_data))[0]         if isinstance(ext, str):             exts.append('http://www.youtube.com/'+ext.replace(' ','')) 

and then:

    ext in exts:         description = description(ext)         embed = embed(ext) 

i added isinstance() lines try , see problem was. when 'str' changed 'unicode', exts list empty (meaning strings, not unicode (or navigablestrings?)). i'm quite confused...

description = description(ext) replaces function string after first iteration in loop. same embed.


Comments

Popular posts from this blog

How do you change vbulletin's home page to the forums instead of the default (CMS or Activity Stream)? -

c++ - Troubles when compiling phash program -