我正在尝试使用 Qt 从以下网址下载 html 代码:
http://www.ncbi.nlm.nih.gov/entrez/query.fcgi?db=核苷酸&cmd=search&term=AB100362
此网址将重定向到
www.ncbi.nlm.nih.gov/nuccore/27884304
我尝试通过以下方式做到这一点,但我什么也得不到。它适用于某些网页,例如 www.google.com,但不适用于此 NCBI 页面。有什么办法可以得到这个页面??
QNetworkReply::NetworkError downloadURL(const QUrl &url, QByteArray &data)
{
QNetworkAccessManager manager;
QNetworkRequest request(url);
QNetworkReply *reply = manager.get(request);
QEventLoop loop;
QObject::connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
loop.exec();
if (reply->error() != QNetworkReply::NoError)
{
return reply->error();
}
data = reply->readAll();
delete reply;
return QNetworkReply::NoError;
}
void GetGi()
{
int pos;
QString sGetFromURL = "http://www.ncbi.nlm.nih.gov/entrez/query.fcgi";
QUrl url(sGetFromURL);
url.addQueryItem("db", "nucleotide");
url.addQueryItem("cmd", "search");
url.addQueryItem("term", "AB100362");
QByteArray InfoNCBI;
int errorCode = downloadURL(url, InfoNCBI);
if (errorCode != 0 )
{
QMessageBox::about(0,tr("Internet Error "), tr("Internet Error %1: Failed to connect to NCBI.\t\nPlease check your internect connection.").arg(errorCode));
return "ERROR";
}
}