zoukankan      html  css  js  c++  java
  • 寒假学习报告10

    今天继续研究了爬虫

    遇到了一些问题,各种查阅资料才得以解决。

    response.xpath.extract()爬取的值里面含有 ,
    如何去掉呢?需要normalize-space()
    比如:
    response.xpath('//div[@class=""]/text()').extract()
    使用normalize-space()后:
    response.xpath('normalize-space(//div[@class=""]/text())').extract()

    在xpath的外面还可以用
    name = name.replace(' ', '').replace(' ', '').replace(' ', '')
    name = name.replace('
    ', '')
    name = name.replace('	', '')
    name = name.replace(' ', '')
    来去除 空格


    scrapy 爬虫爬到<div>标签里面包含<p>标签
    我想爬取div标签中的所有的内容,但是里面有p标签,
    直接response.xpath('//div[@class=""]/text()').extract()的话是没有<div>里的<p>中的内容的,
    需要response.xpath('//div[@class=""]/descendant::text()').extract()

    scrapy中parse函数向其他函数传参

    def parse(self, response):
        yield scrapy.Request(url,callback=self.next,meta={'rname':'2'})
    def next(self,response):
        print(response.meta['rname'])

    然后又把上一个程序优化了一下

  • 相关阅读:
    ORACLE AWR 和 ASH
    11g RAC R2 日常巡检--Grid
    Linux中重命名文件
    Xshell4连接Linux后 win快捷键锁屏
    vim 删除临时文件
    shell--read命令
    shell基础篇(一)从hello world开始
    ORACLE--分区表数据清理
    Shell—学习之心得
    awk 手册--【转载】
  • 原文地址:https://www.cnblogs.com/baimafeima/p/12292978.html
Copyright © 2011-2022 走看看