首页
学习
活动
专区
圈层
工具
发布
    • 综合排序
    • 最热优先
    • 最新优先
    时间不限
  • 来自专栏python3

    requests项目实战--抓取猫眼电影排行

    except Exception:             return None     def get_content(self, html):         items = []         # normalize-space ']/dd")         for i in all_list:             item = Item()             item.movie_name = i.xpath("normalize-space //p[@class='name']/a/text())")             item.to_star = i.xpath("normalize-space(. //p[@class='star']/text())")             item.release_time = i.xpath("normalize-space(. class='score']/i/text()")             item.score = x + y             item.picture_address = i.xpath("normalize-space

    50821发布于 2020-01-21
  • 来自专栏python3

    requests项目实战--抓取百度热搜

    except Exception:             return None     def get_content(self, html):         items = []         # normalize-space item = Item()             id += 1  # 自增1             item.id = id             item.title = i.xpath("normalize-space //a[@class='opr-toplist1-cut']/text())")             item.url = 'https://www.baidu.com' + i.xpath("normalize-space //a[@class='opr-toplist1-cut']/@href)")             item.hits = i.xpath("normalize-space(.

    1K30发布于 2020-08-24
  • 来自专栏思考是一种快乐

    Scrapy 入门教程

    itemscope itemtype="h'>, <Selector xpath=u"descendant-or-self::div[@class and contains(concat(' ', normalize-space itemscope itemtype="h'>, <Selector xpath=u"descendant-or-self::div[@class and contains(concat(' ', normalize-space itemscope itemtype="h'>, <Selector xpath=u"descendant-or-self::div[@class and contains(concat(' ', normalize-space itemscope itemtype="h'>, <Selector xpath=u"descendant-or-self::div[@class and contains(concat(' ', normalize-space itemscope itemtype="h'>, <Selector xpath=u"descendant-or-self::div[@class and contains(concat(' ', normalize-space

    99020发布于 2019-09-23
  • 来自专栏最新Python入门基础合集

    Python爬虫实战:豆瓣TOP250,从底层到代码的超详细讲解,新手看完必会!

    \n '] 看到输出的结果中标题前后都有很多空格和换行符 使用normalize-space来消除 for tr in trs: #获取标题 title = tr.xpath(" normalize-space(td[2]/div/a/text())") print(title) #输出结果:We Sing. We Steal Things. normalize-space(…):这是一个XPath函数,用于对给定的字符串进行标准化处理,删除字符串前后的空白字符(如空格、换行符等),并将字符串中间的多个连续空白字符替换为一个空格 td[2]/div/p/text()”)[0],使用下标获取第一个元素,变成字符串,然后对字符串进行拆分 for tr in trs: #获取标题 title = tr.xpath("normalize-space 清除空格 #获取评分人数 scoring_number = tr.xpath('normalize-space(td[2]/div/div/span[3]/text())') print(scoring_number

    1.7K11编辑于 2024-11-20
  • 来自专栏cuijianzhe

    Scrapy学习

    itemscope itemtype...'>, <Selector xpath="descendant-or-self::div[@class and contains(concat(' ', <em>normalize-space</em> itemscope itemtype...'>, <Selector xpath="descendant-or-self::div[@class and contains(concat(' ', normalize-space itemscope itemtype...'>, <Selector xpath="descendant-or-self::div[@class and contains(concat(' ', <em>normalize-space</em> itemscope itemtype...'>, <Selector xpath="descendant-or-self::div[@class and contains(concat(' ', normalize-space itemscope itemtype...'>, <Selector xpath="descendant-or-self::div[@class and contains(concat(' ', <em>normalize-space</em>

    1.6K20编辑于 2022-06-14
  • 来自专栏数据科学学习手札

    xpath进阶用法

    2.15 对提取内容中的空格进行规范化处理   在xpath中我们可以使用normalize-space对目标内容中的多余空格进行清洗,其作用是删除文本内容之前和之后的所有\s类的内容,并将文本中夹杂的两个及以上空格转化为单个空格 ,下面比较使用normalize-space前后对提取结果的影响: '''清洗前''' tree.xpath("//p[@class='text-muted']/text()") ? '''清洗后''' tree.xpath("normalize-space(//p[@class='text-muted']/text())") ?    使用normalize-space之后得到的结果更加的规整,可以提高爬取数据的效率。

    3.9K40发布于 2019-06-18
  • 来自专栏python3

    Selenium 动态爬取51job招聘信息

    etree.HTML(htmlcontent)             item = Item()             # 岗位名             job_name = html_xpath.xpath("normalize-space             item.job_name = job_name             # 公司名             company_name = html_xpath.xpath("normalize-space             item.company_name = company_name             # 工作地点             work_place = html_xpath.xpath("normalize-space ()             item.work_place = work_place             # 薪资             salary = html_xpath.xpath("normalize-space ")             item.salary = salary             # 发布时间             release_time = html_xpath.xpath("normalize-space

    1.6K40发布于 2020-11-03
  • 来自专栏Lan小站

    xpath里如何定义包含一个class

    normalize-space(string?) 所有在字符串头和尾的空白字符都被移除,或者将字符间两个及以上的空白字符置换成单一空格。

    67620编辑于 2022-07-13
  • 来自专栏python3

    Selenium&Chrome实战:动态爬取51job招聘信息

    htmlcontent)             item = Item()             # 岗位名             item.job_name = html_xpath.xpath("normalize-space //div[@class='cn']/h1/text())")             # 公司名             item.company_name = html_xpath.xpath("normalize-space             /p[@class='cname']/a/text())")             # 工作地点             item.work_place = html_xpath.xpath("normalize-space ltype']/text())").split('|')[0].strip()             # 薪资             item.salary = html_xpath.xpath("normalize-space [@class='cn']/strong/text())")             # 发布时间             item.release_time = html_xpath.xpath("normalize-space

    2.1K20发布于 2020-01-07
  • 来自专栏程序员八阿哥

    微软开源最强Python自动化神器Playwright!不用写一行代码!

    ") page.fill("input[name=\"wd\"]", "jingdong") page.click("text=\"京东\"") # Click //a[normalize-space page.expect_navigation(): with page.expect_popup() as popup_info: page.click("//a[normalize-space

    2K10发布于 2020-12-25
  • 来自专栏蛮三刀的后端开发专栏

    【scrapy】scrapy爬取京东商品信息——以自营手机为例

    /@title').extract() item['phone_id'] = each_id item['phone_name'] = response.xpath('normalize-space /@title').extract() item['phone_id'] = each_id item['phone_name'] = response.xpath('normalize-space

    2.7K20发布于 2019-03-26
  • 来自专栏GitHub专栏

    新一代爬虫利器 Playwright!

    input[name="wd"]") page.fill("input[name="wd"]", "jingdong") page.click("text="京东"") # Click //a[normalize-space with page.expect_navigation(): with page.expect_popup() as popup_info: page.click("//a[normalize-space

    2.6K40编辑于 2022-09-02
  • 来自专栏码农架构

    微软出了一个 Python 小白神器!

    input[name="wd"]") page.fill("input[name="wd"]", "jingdong") page.click("text="京东"") # Click //a[normalize-space with page.expect_navigation(): with page.expect_popup() as popup_info: page.click("//a[normalize-space

    2K30发布于 2021-10-12
  • 来自专栏若城技术专栏

    爬虫入门指南(1):学习爬虫的基础知识和技巧

    获取字符串的长度 xpath_expression = 'string-length("Hello World")' # 移除字符串两端的空白字符并压缩中间的空白字符 xpath_expression = 'normalize-space normalize-space():移除字符串两端的空白字符并压缩中间的空白字符。 count():计算节点的数量。 使用XPath解析网页 使用XPath解析网页可以方便地定位和提取需要的数据。

    1.4K10编辑于 2024-02-29
  • 来自专栏未闻Code

    一日一技:自动提取任意信息的通用爬虫

    清洗干净以后,我们再使用XPath:normalize-space(string())提取出页面上的文本,把文本发给GPT,就可以正常解析内容了。

    68420编辑于 2023-12-14
  • 来自专栏Golang开发

    Python爬虫——电影top榜

    image-link']/img[@class='board-img']/@data-src").extract_first() movie['star'] = item.xpath("normalize-space

    72210发布于 2019-05-29
  • 来自专栏F12sec

    经验分享 | 利用xpath爬取edu漏洞列表

    再用lxml中_element的xpath来将文本内容转化为值 这里要注意的是在我们原有的路径上要加上”/text()”否则识别不出来,其次是用normalize-space将爬取的内容中的空格去除,

    63420编辑于 2022-09-29
  • 来自专栏python3

    Python自动化开发学习-Scrapy

    class是变量,这个也不能用加号,就要用这个函数做拼接: response.xpath('//div[contains(concat(" ", @class, " "), " test ")]') normalize-space 总之这个是最终的解决方案: response.xpath('//div[contains(concat(" ", normalize-space(@class), " "), " test ")]') /div[@class="news-content"]' '//a[contains(concat(" ", normalize-space(@class), " "), /div[@class="news-content"]' '//a[contains(concat(" ", normalize-space(@class), " "), /div[@class="news-content"]' '//a[contains(concat(" ", normalize-space(@class), " "),

    1.8K10发布于 2020-01-08
  • 来自专栏软件测试

    测试工程师必备:深度剖析XPath与CSS Selector的选型与高阶用法

    ()='登录']:精确文本匹配//a[contains(text(), '忘记密码')]:文本包含//input[starts-with(@id, 'email_')]:ID以指定前缀开头//div[normalize-space ()='登录']:精确文本匹配//a[contains(text(), '忘记密码')]:文本包含//input[starts-with(@id, 'email_')]:ID以指定前缀开头//div[normalize-space

    37310编辑于 2025-08-20
  • 来自专栏进击的Coder

    Scrapy框架的使用之Scrapy入门

    1. quote.css('.text') [<Selector xpath="descendant-or-self::*[@class and contains(concat(' ', <em>normalize-space</em> 2. quote.css('.text::text') [<Selector xpath="descendant-or-self::*[@class and contains(concat(' ', normalize-space

    1.7K30发布于 2018-06-25
领券