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'])

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

  • 相关阅读:
    有用的Python模块
    Python中for循环搭配else的陷阱
    MySQL实用操作
    Pycharm常用快捷键
    MySQL基础
    HTML基础
    MySQL基础
    HTTP连接管理
    TCP连接的建立和终止
    TCP数据流
  • 原文地址:https://www.cnblogs.com/baimafeima/p/12292978.html
Copyright © 2011-2022 走看看