小编Yue*_* Ma的帖子

Python URL TypeError:'str'对象不可调用

我正在尝试编写一个小型的Web请求程序来获得一些流行的Instagram用户(这是python 3).

final_list = [];
for idx in range(1, 5, 1):
    url = "http://zymanga.com/millionplus/" + 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);
Run Code Online (Sandbox Code Playgroud)

第一次迭代运行良好(我能够在第一页上获得用户),但是在第二次迭代中,我正在编写以下错误:

Traceback (most recent call last):
  File ".\web_search.py", line 8, in <module>
    url = "http://zymanga.com/millionplus/" + str(idx) + "f";
TypeError: 'str' object is not callable
Run Code Online (Sandbox Code Playgroud)

能不能让我知道可能导致问题的原因,试图调试但无法解决问题.谢谢!

python http httprequest web

-1
推荐指数
1
解决办法
1525
查看次数

标签 统计

http ×1

httprequest ×1

python ×1

web ×1