zoukankan      html  css  js  c++  java
  • 记录犯得最可笑的错误

    代码引用

            detail_lists = response.xpath('//section[@class="section board-list board-list-collapse"]/ul/li')
            #'//section[@class="section board-list board-list-collapse"]/ul/li'
            print('-----> ????????????????????????')
            print(detail_lists)
            for detail in detail_lists:
                novelimg = detail.xpath('./a/img/@src').extract_first()
                # '//*[@id="navList"]/section/ul/li[32]/a/img'
                novelname = detail.xpath('./span/a[1]/@title').extract_first()
                # '//*[@id="navList"]/section/ul/li[32]/span/a[1]'
                href = detail.xpath('./a/@href').extract_first()
                # '//*[@id="navList"]/section/ul/li[32]/a'
                author = detail.xpath('./span/a[2]/text()').extract_first()
                # '//*[@id="navList"]/section/ul/li[32]/span/a[2]'
                state = detail.xpath('./img[@class="topss png_bg"]/@src').extract_first()
                # '//*[@id="navList"]/section/ul/li[32]/img'
                print('图片:', novelimg)
                print('小说名称:', novelname)
                print('链接:', href)
                print('作者是:', author)
                if 'only2.png' in state:
                    state = '连载中'
                else:
                    state = '完结'
                print('状态是:', state)
    

    一直解析不出标签内容和属性值的原因

          for detail in detail_lists:
                novelimg = response.xpath('./a/img/@src').extract_first()
          # 将for语句中的xpath解析写成了response.xpath,应该是detail.xpath
          # 写代码逻辑错误,跳过错误,不是一行行写的,跳跃性敲代码,拼凑的代码,很恶心
    
  • 相关阅读:
    面向对象1 继承与接口
    简易版爬虫(豆瓣)
    调用模块与包
    正则表达式2 以及configparser模块,subprocess模块简单介绍
    正则表达式(re模块)
    sys,logging,json模块
    常用模块(time,os,random,hashlib)
    内置函数与匿名函数
    day 19 yeild的表达式 面向过程 内置函数
    mysql中写存储过程加定时任务
  • 原文地址:https://www.cnblogs.com/shiyishou/p/14192569.html
Copyright © 2011-2022 走看看