尝试其他答案时,这些解决方案不起作用,尝试这些方法时,输出的字符串相同。
我正在尝试使用Python 2.7进行网络抓取。我已经下载了网页,其中包含一些字符,这些字符的形式x似乎是120代表ASCII代码。我尝试使用HTMLParser()和decode()方法,但似乎无济于事。请注意,我在网页上所获得的格式仅为这些字符。例:
Blasterjaxx 
Run Code Online (Sandbox Code Playgroud)
请指导我使用Python解码这些字符串。我已经阅读了其他答案,但是解决方案似乎对我不起作用。
#include <iostream>
#include <string>
#include <stdlib.h>
using namespace std;
int main()
{
string x;
cin>>x;
if(strcmp(&x.at(0), "M") == 0)
{
cout<<"midget ";
}
else if(strcmp(&x.at(0), "J") == 0)
{
cout<<"junior ";
}
else if(strcmp(&x.at(0), "S") == 0)
{
cout<<"senior ";
}
else
{
cout<<"invalid code";
}
if(strcmp(&x.at(1), "B") == 0)
{
cout<<"boys";
}
else
{
cout<<"girls";
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我已经使用上面的代码来比较MB应该返回"侏儒男孩",但它继续下降到其他并返回"无效的codeboys".不知何故第二个条件正常.我的诊断告诉我,在第一次比较它返回66.我猜这是"M"的ASCII代码.但是我现在如何解决我的问题呢?