求教各位大神,请问有什么错误。系统提示索引超出范围,大概就是标红的地方,求教

ilove_python 2019-04-20 10:30:29
import urllib.request as req
from lxml import etree
i =2
while i<=6:
html =req.urlopen("http://site.gzcc.cn/html/szdw/"+str(i)+".html")
content =html.read()
selectors =etree.HTML(content)
j=1
while j<=7:
list1 =selectors.xpath("/html/body/div[4]/div/div[1]/div[2]/ul/a["+str(j)+"]/li/div/div[2]/p[1]/img")
list2 =selectors.xpath("/html/body/div[4]/div/div[1]/div[2]/ul/a["+str(j)+"]/li/div/div[2]/p[2]/img")
f =open("test.txt","a")
f.write(list1[0]+"--------"+list2[0]+"\n")
f.close()
j+=1
i+=1

...全文
92 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

37,720

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • IT.BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧