AttributeError:' NoneType'对象没有属性' group'错误

时间:2015-06-01 03:14:39

标签: python attributeerror

try:
            res = self.browser.open('https://login.facebook.com/login.php?login_attempt=1',form_data)
            response = res.read()
            self.fbid = re.search('https://www.facebook.com/(.*)\?sk=info',response)
            self.fbid = re.search('https://www.facebook.com/(.*)',self.fbid.group(1))
            self.fbid = re.search('https://www.facebook.com/(.*)',self.fbid.group(1))
        except urllib2.HTTPError,e :
            print "****exception****inside login  error code: %s" % (e.code)
        res.close()
    except urllib2.HTTPError,e :
         print "****exception****inside login  error code: %s" % (e.code)

    #print " server Response Code: %s " % (res.code)

我得到了这个

File "facebotv2.py", line 122, in login
    self.fbid = re.search('https://www.facebook.com/(.*)',self.fbid.group(1))
AttributeError: 'NoneType' object has no attribute 'group'

1 个答案:

答案 0 :(得分:3)

在第一次正则表达式搜索后,

public class MyClass { public int Id { get; set; } public string Name { get; set; } } self.fbid。这可能意味着您没有找到匹配项。如果您想要阻止错误,您可以有条件地仅使用None

继续搜索初始搜索的结果