【问题标题】:python http page without heads没有头的python http页面
【发布时间】:2013-07-11 16:54:41
【问题描述】:

我必须通过大量的 ips 搜索特定的 url。我在python中编写了一个脚本来检查端口是否打开,然后使用httplib检查url是否存在,它工作得很好!我的问题是我得到了太多误报,因为一些网络设备在请求我的页面时给出状态 200,并在正文上返回一个带有 400 错误的页面

这是我的代码:

def MyPage(self,ip):
    try:
        conn = httplib.HTTPConnection(ip)
        conn.request("HEAD", "/path/to/mypage.php")
        resp = conn.getresponse()
        if (resp.status == 200):
            return True
        else :
            return False
    except :
        return False

【问题讨论】:

    标签: python beautifulsoup httplib getresponse


    【解决方案1】:

    我解决了我在页面正文上检查标题标签的问题

    def Mypage(self,ip):
        try:
            conn = httplib.HTTPConnection(ip)
            conn.request("GET", "/path/to/mypage.php")
            resp = conn.getresponse()
            if (resp.status == 200):
                html = BeautifulSoup(resp.read())
                data = html.find('title')
                titulo = str(data.contents[0])
                if titulo == "THE TITLE":
                    return True
                else:
                    return False
            else :
                return False
        except :
            return False
    

    【讨论】:

      猜你喜欢
      • 2013-01-25
      • 2016-02-18
      • 1970-01-01
      • 2018-04-05
      • 2019-07-15
      • 1970-01-01
      • 1970-01-01
      • 2010-11-24
      • 2011-01-02
      相关资源
      最近更新 更多