What can be used instead of the parse_qs function

I have the following code to parse a youtube channel and return a YouTube movie id. How can I rewrite this as compatible with python 2.4, which I suppose does not support the parse_qs function?

 YTSearchFeed = feedparser.parse("http://gdata.youtube.com" + path) videos = [] for yt in YTSearchFeed.entries: url_data = urlparse.urlparse(yt['link']) query = urlparse.parse_qs(url_data[4]) id = query["v"][0] videos.append(id) 
+4
source share
2 answers

I assume that your existing code works in version 2.6 or something newer, and you are trying to return to 2.4? parse_qs used in the cgi module before it was ported to urlparse . Try import cgi , cgi.parse_qs .

Inspired by a TryPyPy comment, I think you could run your source in any environment by doing the following:

 import urlparse # if we're pre-2.6, this will not include parse_qs try: from urlparse import parse_qs except ImportError: # old version, grab it from cgi from cgi import parse_qs urlparse.parse_qs = parse_qs 

But I do not have 2.4 to try this, therefore no promises.

+11
source

I tried this, and yet .. it did not work.

It is easier to simply copy the parse_qs / qsl functions from the cgi module to the urlparse module.

The problem is resolved.

-1
source

Source: https://habr.com/ru/post/1334916/


All Articles