开发者

Python 3.[12] urllib

开发者 https://www.devze.com 2023-03-28 14:39 出处:网络
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

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

精彩评论

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