吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 937|回复: 0
收起左侧

[讨论] Qt获取百度搜索页面内容获取失败

[复制链接]
海军 发表于 2020-12-27 13:08
本帖最后由 海军 于 2021-1-5 09:42 编辑

[C++] 纯文本查看 复制代码
QString url = "https://www.baidu.com/s?ie=utf-8&wd=";
url.append(keyword);
QNetworkRequest request;
QNetworkAccessManager* naManager = new QNetworkAccessManager(this);
QMetaObject::Connection connRet = QObject::connect(naManager,
                                                   SIGNAL(finished(QNetworkReply*)),
                                                   this, SLOT(requestFinished(QNetworkReply*)));

request.setRawHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36");
request.setRawHeader("Accept","text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9");
request.setRawHeader("Host","www.baidu.com");
request.setRawHeader("Connection","keep-alive");
request.setRawHeader("Upgrade-Insecure-Requests","1");
request.setRawHeader("Accept-Encoding","deflate");
QSslConfiguration config;
config.setPeerVerifyMode(QSslSocket::VerifyNone);
config.setProtocol(QSsl::TlsV1_2);
request.setSslConfiguration(config);
request.setUrl(QUrl(url));
QNetworkReply *reply = naManager->get(request);
reply->ignoreSslErrors();

[C++] 纯文本查看 复制代码
void Widget::requestFinished(QNetworkReply* reply){
int httpStatus = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
qWarning() << httpStatus<<endl;
qWarning() << reply->readAll();
}

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2025-1-16 16:38

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表