【问题标题】:Detect if beautifulsoup found text on a page or not检测 beautifulsoup 是否在页面上找到文本
【发布时间】:2022-01-12 01:09:24
【问题描述】:
soup.body.findAll(text='No Results Found')

基本上我需要类似的东西

if soup.body.findAll(text='No Results Found') does find this text:
   print("URL doesn't exist")

真的希望这不是一个愚蠢的问题,但如果已经被问到,我不确定要查找什么来找到答案

【问题讨论】:

    标签: python beautifulsoup


    【解决方案1】:

    soup.body.findAll(text='No Results Found') 搜索具有确切文本“未找到结果”的元素。

    但我认为你的问题根本不需要beautifulsoup。要查看字符串“未找到结果”是否位于页面上,您只需尝试在 HTML 中找到您的字符串:

    import requests
    
    html = requests.get(your_url)
    if 'No Results Found' in html:
        print("URL doesn't exist")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-22
      • 1970-01-01
      • 1970-01-01
      • 2012-03-28
      • 1970-01-01
      • 2012-03-20
      相关资源
      最近更新 更多