IndexError: list index out of range

来源:14-12 获取和解析详情页 - 1

朗月清风

2019-06-13

all_divs = sel.xpath("//div[starts-with(@id, ‘post-’)]")
all_divs取不到值
执行到 topic_item = all_divs[0] 就会报 IndexError: list index out of range
又遇到同样问题的吗?还请指导,谢谢了

写回答

1回答

bobby

2019-06-14

你在运行这个代码之前打印一下返回的html,先确定一下html中是否有这个元素的存在

0
1
朗月清风
非常感谢!
2019-06-27
共1条回复

Python爬虫工程师实战 大数据时代必备

慕课网严选精品教程,高质量内容+服务!

2377 学习 · 1158 问题

查看课程