jeudi 29 juin 2017

Python URL TypeError: 'str' object is not callable

I am trying to write a small web request program to get some of the popular Instagram users (this is python 3).

final_list = [];
for idx in range(1, 5, 1):
    url = "http://ift.tt/2fpFTHU" + str(idx) + "f"; # idx is for page number
    print(url);
    headers = {...omitted header details...};
    req = urllib.request.Request(url, None, headers);
    with urllib.request.urlopen(req) as f:
        str = f.read().decode('utf-8');
    initial_list = re.findall(r'target=\"_blank\">([^<]+?)</a>,', str);
    for item in initial_list:
        final_list.append(item);

The first iteration works well (and I am able to get the users on the first page), however on the second iteration, I am encounting the following error:

Traceback (most recent call last):
  File ".\web_search.py", line 8, in <module>
    url = "http://ift.tt/2fpFTHU" + str(idx) + "f";
TypeError: 'str' object is not callable

Could you please let me know what might caused the problem, tried to debug but couldn't resolved it. Thanks!




Aucun commentaire:

Enregistrer un commentaire