QtWebkit读取html元素
来源:互联网 发布:java哈希表 编辑:程序博客网 时间:2024/06/06 07:41
闲着无聊做个小工具抓特定网站一些免费账号(不通用)。
主要用了Qt5.5.1种的webkit,具体看代码 就不说了,代码很简单:
void MainWindow::on_pushButton_clicked(){ ui->pushButton->setEnabled(false); QString WwwUrl = "http://www.ishadowsocks.net/"; QWebPage UrlPage; UrlPage.mainFrame()->load(QUrl(WwwUrl)); QEventLoop loop; QObject::connect(&UrlPage ,SIGNAL(loadFinished(bool)) ,&loop ,SLOT(quit())); loop.exec(); QWebFrame *UrlFrame = UrlPage.currentFrame(); QWebElement doc = UrlFrame->documentElement(); QWebElement IdFree = doc.findFirst("#free"); QWebElementCollection ServerGroup = IdFree.findAll(".col-sm-4"); QString Json = "{\n\"configs\" : [\n"; QString ConfigData; for(int Server= 0; Server< ServerGroup.count();Server++) { QWebElement childServer = ServerGroup.at(Server); QWebElementCollection childGroup = childServer.findAll("h4"); QString tmpdata; QString ServerName = childGroup.at(0).toPlainText(); QString ServerPort = childGroup.at(1).toPlainText(); QString ServerPasswd = childGroup.at(2).toPlainText(); QString ServerMethod = childGroup.at(3).toPlainText(); QRegExp rx(":"); ServerName = ServerName.mid(rx.indexIn(ServerName)+1); ServerPort = ServerPort.mid(rx.indexIn(ServerPort)+1); ServerPasswd = ServerPasswd.mid(rx.indexIn(ServerPasswd)+1); ServerMethod = ServerMethod.mid(rx.indexIn(ServerMethod)+1); tmpdata=QString(" {\n\"server\" : \"%1\",\n\"server_port\" : %2,\n\"password\" : \"%3\",\n\"method\" : \"%4\",\n\"remarks\" : \"\"}\n,\n")\ .arg(ServerName)\ .arg(ServerPort)\ .arg(ServerPasswd)\ .arg(ServerMethod); ConfigData+=tmpdata; } ConfigData.remove(ConfigData.length()-2,1); QString config; config.sprintf("],\n\"strategy\" : null,\n\"index\" : 0,\n\"global\" : false,\n\"enabled\" : true,\n\"shareOverLan\" : true,\n\"isDefault\" : false,\n\"localPort\" : 1080,\n\"pacUrl\" : null,\n\"useOnlinePac\" : false,\n\"availabilityStatistics\" : false}"); ConfigData+=config; Json +=ConfigData; WriteFile(Json); ui->pushButton->setEnabled(true);}void MainWindow::WriteFile(QString data){// QString Path = QCoreApplication::applicationDirPath(); QString Path = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation); QString configname = "gui-config.json"; QString FilePath = Path+"/"+configname; QFile file(FilePath); bool ok = file.open(QIODevice::WriteOnly | QIODevice::Text); if(!ok) { QMessageBox::information(this,"Error","File OPen faild!"); return; } QTextStream out(&file); out<<data.toUtf8()<<endl; file.close(); QMessageBox::information(this, "Sucess","gui-config.json已输出到桌面!");}
源码下载
0 0
- QtWebkit读取html元素
- js读取html元素属性
- QtWebKit
- JAVASRIPT读取HTML元素的自定义属性。
- html img 元素 读取width 的问题
- thymleaf读取内容中的html元素
- pyqt通过qtwebkit嵌入显示html与js
- html多种方法读取表单的元素值
- HTML 元素
- HTML元素
- Html元素
- html元素
- HTML 元素
- HTML元素
- HTML元素
- html元素
- html元素
- html 元素
- 如何阅读一本书(程序员)
- 安卓Andriod使用入门(二十)【颜色对话框】
- 数据挖掘分类算法之贝叶斯分类法原理及C++实现
- leetcode(30).110. Balanced Binary Tree
- 莎士比亚的对白
- QtWebkit读取html元素
- 与他人分享是学习过程中效率最高的方法
- 面向对象内容
- [入门-1]基础类型之列表
- Log4j 打印堆栈信息
- [kuangbin带你飞]专题九 连通图 B - Network (双连通分量(割点)(割边,桥))(模板)
- 太多的.hive-stagingxxx文件的处理
- 工程师SwarmKit初体验 比传统集群工具更方便
- Material Design使用之SnackBar