蜘蛛没有找到任何页面

时间:2016-04-05 08:09:21

标签: python scrapy scrapy-spider

我正在尝试运行我的第一只蜘蛛而是在挣扎。我可以让它运行,但它没有找到任何页面。如果有人有任何想法,他们将非常感激。 我的代码是:

#include<iostream>
#include<string>

using namespace std;

string Encrypt(string&, int &);// Function Prototype.  This declares Encrypt to be a function that needs one variable as string and another as interger as arguments. Reference operator & in prototype
string Decrypt(string&, int &);//Function Prototype.  This declares Decrypt to be a function that needs one variable as string and another as interger as arguments. Reference operator & in prototype

int main()
{

string text;//the string that holds the user input

int key;//key holds the number by which the user wants the alphabets to be shifted

cout << "Enter your phrase: " << endl;
getline(cin, text);//gets the user input ( including spaces and saves it to the variable text)

cout << "Please choose a number(key) for which you wants the alphabets to be shifted:  " << endl;
/*Note: the key can either be positive (forward shifting), negative (backward shifting) or zero (no shifting)*/

cin >> key;//User input for number by which alphabets are going to be shifted

string kolo = Encrypt(text, key);

cout << "Encrypted Message: " << kolo << endl;//Function call to display encrypted message

//Decrypt(Encrypt(text, key), key);

cout << "Decrypted Message: " << Decrypt(kolo, key)<< endl;//Function call to display decrypted message

//system("Pause");

return 0;
}



string Encrypt(string& Source, int& c)
{
char fUpperCase[26] = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' };//Initialization of class member
char fLowerCase[26] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' };//Initialization of class member

int z;//z holds the value (int) of the length of the user input ( including spaces)
z = (int)Source.length();   /*give the variable z the value of the user input length and length is normally an unsigned long integer hence
                            we have to typecast it*/

/*counter that makes it keep looping until it "encrypts" all of the user input (that's why it keeps looping while its less than z)*/
for (int i = 0; i < z; i++)
{
    for (int j = 0; j < 26; j++)
    {
        if (Source[i] == fLowerCase[j] || Source[i] == fUpperCase[j])
        {
            //text[i] = fLowerCase[j];

            if (c > 0)
            {
                //another counter that loops forwards key times by incrementing method
                for (int counter = 0; counter < c; counter++)
                {
                    /*it checks if the letter text[x] is 'z' and if it is 'z' it will make it 'a'*/
                    if (Source[i] == 'z')
                    {
                    Source[i] = 'a';
                    }

                    else if (Source[i] == 'Z')
                    {
                    Source[i] = 'A';
                    }

                    else
                    {
                    Source[i]++;
                    }

                }
            }

            else    if (c < 0)
            {
                //another counter that loops backwards key times by decrementing method
                for (int counter = 0; counter < abs(c); counter++)
                {
                    /*it checks if the letter text[x] is 'a' and if it is 'a' it will make it 'z'*/
                    if (Source[i] == 'a')
                    {
                        Source[i] = 'z';
                    }

                    else if (Source[i] == 'A')
                    {
                        Source[i] = 'Z';
                    }

                    else
                    {
                        Source[i]--;
                    }
                }
            }

            else
            {
                Source[i];//No alphabet shifts
            }

        }

        else {
                continue;
             }

        break;
    }

}

return Source;
}

string Decrypt(string& EncryptedMessage, int& c)
{
int y;//z holds the value (int) of the length of the user input ( including spaces)
y = (int)EncryptedMessage.length(); /*give the variable z the value of the user input length and length is normally an unsigned long integer hence
                            we have to typecast it*/


for (int i = 0; i < y; i++)
{

    if (isalpha(EncryptedMessage[i]))//verify if the all members of the encrypted message is alphabet if not the same special character is return whereas if it is alphabet it is eitther incremented or decremented
    {

        if (c > 0)
        {
            //another counter that loops forwards key times by incrementing method
            for (int counter = 0; counter < c; counter++)
            {
                /*it checks if the letter text[x] is 'a' and if it is 'z' it will make it 'a'*/
                if (EncryptedMessage[i] == 'a')
                {
                    EncryptedMessage[i] = 'z';
                }

                else if (EncryptedMessage[i] == 'A')
                {
                    EncryptedMessage[i] = 'Z';
                }

                else
                {
                    EncryptedMessage[i]--;
                }

            }
        }

        else    if (c < 0)
        {
            //another counter that loops backwards key times by decrementing method
            for (int counter = 0; counter < abs(c); counter++)
            {
                //it checks if the letter text[x] is 'a' and if it is 'a' it will make it 'z'
                if (EncryptedMessage[i] == 'z')
                {
                    EncryptedMessage[i] = 'a';
                }

                else if (EncryptedMessage[i] == 'Z')
                {
                    EncryptedMessage[i] = 'A';
                }

                else
                {
                    EncryptedMessage[i]++;
                }
            }
        }

        else
        {
            EncryptedMessage[i];//No alphabet shifts
        }

    }

    //cout << "Decrypted Message: " << EncryptedMessage << endl;//Function call to display decrypted message


}
return EncryptedMessage;
}

提前致谢。

1 个答案:

答案 0 :(得分:0)

xpath表达式中有错误,因此sites变量为空。

您可以通过scrapy shell

检查您的xpath
scrapy shell 'https://uk.hotels.com/hotel/details.html?FPQ=6&WOE=1&q-localised-check-out=04/04/2016&WOD=7&q-room-0-children=0&pa=1&tab=description&JHR=8&q-localised-check-in=03/04/2016&hotel-id=424807&q-room-0-adults=2&YGF=2&MGT=1&ZSX=0&SYE=3'
In [4]: response.xpath('//ul[@class="directory-url"]/li')
Out[4]: []
inspect_response(response, self)方法中

parse

from scrapy.shell import inspect_response
inspect_response(response, self)

start_urls个网页不包含[@class="directory-url"]

的元素
相关问题