如何从python中的200分隔404错误代码子域?

时间:2018-03-30 04:45:33

标签: python python-2.7

这是我的代码,我要做的是分隔400个响应状态代码子域。 如您所见,我在子域索引列表中提供了三个网址。哪个有不同的状态代码

现在我要做的是从它们中分离404错误状态代码。

statuscode = []
statuscode.append(400) 
statuscode.append(403)
statuscode.append(404)

 subdomains = []
    subdomains.append("https://teyrtguhigkfjn.s3.amazonaws.com/")
    subdomains.append("http://google.com")
    subdomains.append("https://lasdfgfldsakjas.s3.amazonaws.com/")



    for x in subdomains:
        url =  x


        try:

            req = requests.get(url)

            req1 = str(req.status_code) + " " + str(url) + '\n'
            req2 = str(req.status_code)
            req3 = str(url)
            print "\n" + str(req1)

            except requests.exceptions.RequestException as e:
            print "Can't make the request to this Subdomain " + str(url) + '\n'


    if statuscode in str(req1):

        print "\nTrying to Collect the URL's whose status is 400, 400, 403"
print str(req2) + ' ' + str(req3)

但我没有成功。请查看问题,我想我知道代码的这一行的问题在哪里如果str(req1)中的状态代码:我的猜测

希望你能解决问题。

谢谢

1 个答案:

答案 0 :(得分:0)

import requests
statuscode = [400, 403, 404]
subdomains = ["https://teyrtguhigkfjn.s3.amazonaws.com/", "http://google.com", "https://lasdfgfldsakjas.s3.amazonaws.com/"]

for url in subdomains:
    try:
        req = requests.get(url)
        req1 = str(req.status_code) + " " + str(url) + '\n'
        req2 = str(req.status_code)
        print "\n" + str(req1)
        if req.status_code in statuscode:             #----->Update
            print "\nTrying to Collect the URL's whose status is 400, 400, 403"
            print str(req2) + ' ' + url
    except requests.exceptions.RequestException as e:
        print "Can't make the request to this Subdomain " + str(url) + '\n'