看店宝随附源码运行出错
发表在Python图书答疑
2020-04-06
悬赏:10 学分
《Python从入门到项目实践》第30章 看店宝(京东版)

是否精华
是
否
版块置顶:
是
否
(1)运行show_window.py时提示crawl.py的这行代码出错:
jd_id = i.find('a', {'class', 'btn btn-default follow'}).get('data-id')
错误提示如下:
File "D:\Python\python从入门到项目实践\30\30\看店宝(京东版)\crawl.py", line 39, in get_rankings
jd_id = i.find('a', {'class', 'btn btn-default follow'}).get('data-id')
TypeError: slice indices must be integers or None or have an __index__ method
请问如何解决?以上代码均为学习码下载资源,无任何修改。
(2)若把上述代码中的get('data-id')改为find('data-id'), 则会提示一下错误:
File "D:\PyCharm\JD\crawl.py", line 47, in get_rankings
jd_id = i.find('a', {'class', 'btn btn-default follow'}).find("data-id")
TypeError: slice indices must be integers or None or have an __index__ method