开发者

Python 3.[12] urllib

i am working on a little script grabbing some files from a website. First i create a list of potential urls within the website. This worked fine with Python 3.1 but not with Python 3.2. I guess it is a question on encoding but i am not sure how to realise it in an elegant way.开发者_如何学JAVA Can you help me?

def get_urls(username, password, userid):
    cj = http.cookiejar.CookieJar()
    opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cj))
    login_data = urllib.parse.urlencode({'login' : username, 'password' : password})
    opener.open(BASE_URL+"/bg/login", login_data)
    url = BASE_URL + "/bg/user/" + userid + "?finished=1"
    resp = opener.open(url)
    result = resp.read()
    txt = result.decode("iso-8859-1")
    liste = (re.findall("/bg/export/[\d]{4,8}",txt))
    return liste


The problem should be here:

login_data = urllib.parse.urlencode({'login' : username, 'password' : password}) opener.open(BASE_URL+"/bg/login", login_data)

urllib.parse.urlencode outputs string not an iterable.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜