【问题标题】:From a list of URLs search each page and return results with matching page type从 URL 列表中搜索每个页面并返回具有匹配页面类型的结果
【发布时间】:2022-01-19 01:08:25
【问题描述】:

我有一个域,我想对其进行广泛搜索,除了结尾之外的所有 URL 都相同,我已将其编译到一个列表中。

目标是搜索这些页面中的每一个并识别返回“未找到页面”错误的页面,并将它们返回到控制台 - 我的搜索将是:

<h1 class="center error-page-center" id="error-message">Oops! We couldn’t find what you wanted.</h1>

我一直在尝试使用 BeutifulSoup 来做到这一点,但到目前为止无济于事

import psycopg2
from bs4 import BeautifulSoup

for page in pages:
    page = connection.cursor.execute("select concat('https:mywebsite/',integervalue) as url from table")
    search = soup.find_all(class_="center error-page-center"):
        if len(search)>0: 
        print ("Needs removal")

考虑到我要搜索几千页,还有其他更有效的方法吗?

我的代码将导致错误,我更感兴趣的是寻找有关如何在 URL 列表中搜索特定文本正文的任何​​建议。 谢谢

【问题讨论】:

    标签: python beautifulsoup


    【解决方案1】:
    for url in urls:
        try:
            urllib2.urlopen(url)
        except urllib2.HTTPError, e:
            # Do something when request fails
            print e.code
        else:
            print(url) # succesfful url
                       # write your code.
    

    Python tool to check broken links on a big urls list

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-02-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-28
      • 2015-09-23
      • 1970-01-01
      相关资源
      最近更新 更多