소스코드 정리
git-svn-id: svn://192.168.0.12/source@50 8346c931-da38-4b9b-9d4c-e48b93cbd075
This commit is contained in:
@@ -17,6 +17,18 @@ int main(int argc, char *argv[])
|
|||||||
a.setApplicationName(QString("Chrome"));
|
a.setApplicationName(QString("Chrome"));
|
||||||
a.setApplicationVersion(QString("39.0.2171.95"));
|
a.setApplicationVersion(QString("39.0.2171.95"));
|
||||||
|
|
||||||
|
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
|
||||||
|
db.setHostName("bigbird.iptime.org");
|
||||||
|
db.setUserName("admin");
|
||||||
|
db.setPassword("admin123");
|
||||||
|
db.setDatabaseName("concepters");
|
||||||
|
|
||||||
|
if (db.open() == false)
|
||||||
|
{
|
||||||
|
cout << "error : db open fail...";
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
SCrawler *process = new SCrawler;
|
SCrawler *process = new SCrawler;
|
||||||
QObject::connect(process, SIGNAL(finished()), QApplication::instance(), SLOT(quit()));
|
QObject::connect(process, SIGNAL(finished()), QApplication::instance(), SLOT(quit()));
|
||||||
|
|
||||||
|
|||||||
@@ -54,90 +54,13 @@ void SCrawler::saveResult(bool ok)
|
|||||||
|
|
||||||
QWebElement p_parse = Find(m_page->currentFrame()->documentElement(),"div","class","row inner");
|
QWebElement p_parse = Find(m_page->currentFrame()->documentElement(),"div","class","row inner");
|
||||||
|
|
||||||
|
QString strIpList = getIpList(p_parse);
|
||||||
//Debug("test.html",m_page->currentFrame()->toHtml());
|
//Debug("test.html",m_page->currentFrame()->toHtml());
|
||||||
//Debug("filtered.html", p_parse.toInnerXml());
|
//Debug("filtered.html", p_parse.toInnerXml());
|
||||||
|
|
||||||
QWebElementCollection trs = p_parse.findAll("tr");
|
//SendIpList(strIpList);
|
||||||
QString DISPLAYINLINE = "{display:inline}";
|
|
||||||
QString DISPLAYNONE = "{display:none}";
|
|
||||||
QString totalResult;
|
|
||||||
|
|
||||||
for(int i = 1; i < trs.count(); i++)
|
Debug(m_strFolder + "proxy.txt",strIpList);
|
||||||
{
|
|
||||||
QWebElementCollection tds = trs.at(i).findAll("td");
|
|
||||||
|
|
||||||
QWebElement firstStyle = trs.at(i).findFirst("style");
|
|
||||||
|
|
||||||
QString strFirstStyle = firstStyle.toInnerXml().trimmed();
|
|
||||||
|
|
||||||
QStringList disinline;
|
|
||||||
QStringList disnone;
|
|
||||||
// {display:inline} {display:none}
|
|
||||||
QStringList strlist = strFirstStyle.split(".", QString::SkipEmptyParts);
|
|
||||||
|
|
||||||
foreach(QString str, strlist)
|
|
||||||
{
|
|
||||||
if(str.trimmed().right(DISPLAYINLINE.length()).compare(DISPLAYINLINE) == 0)
|
|
||||||
{
|
|
||||||
disinline.append(str.trimmed().left(str.trimmed().length() - DISPLAYINLINE.length()));
|
|
||||||
// cout << DISPLAYINLINE.toStdString() << " : " << str.trimmed().left(str.trimmed().length() - DISPLAYINLINE.length()).toStdString() << endl;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
disnone.append(str.trimmed().left(str.trimmed().length() - DISPLAYNONE.length()));
|
|
||||||
// cout << DISPLAYNONE.toStdString() << " : " << str.trimmed().left(str.trimmed().length() - DISPLAYNONE.length()).toStdString() << endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
QString strIpContents = tds.at(1).toInnerXml();
|
|
||||||
foreach(QString str, disinline)
|
|
||||||
{
|
|
||||||
strIpContents.replace(str.trimmed(),"display: inline");
|
|
||||||
}
|
|
||||||
foreach(QString str, disnone)
|
|
||||||
{
|
|
||||||
strIpContents.replace(str.trimmed(),"display:none");
|
|
||||||
}
|
|
||||||
|
|
||||||
// cout << strIpContents.toStdString() << endl;
|
|
||||||
QStringList strIpContentsList = strIpContents.split(QRegExp("[<>]"),QString::SkipEmptyParts);
|
|
||||||
QString result;
|
|
||||||
for(int j = 0; j < strIpContentsList.count(); j++)
|
|
||||||
{
|
|
||||||
QString str1 = strIpContentsList.at(j).trimmed();
|
|
||||||
|
|
||||||
if(str1.at(0) == '/')
|
|
||||||
continue;
|
|
||||||
if(str1.left(4).compare("span") == 0)
|
|
||||||
continue;
|
|
||||||
if(str1.left(3).compare("div") == 0)
|
|
||||||
continue;
|
|
||||||
if(str1.left(5).compare("style") == 0)
|
|
||||||
continue;
|
|
||||||
if(str1.mid(1,3).compare("dis") == 0)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if(j > 0)
|
|
||||||
{
|
|
||||||
QString str2 = strIpContentsList.at(j-1).trimmed();
|
|
||||||
if(str2.right(5).compare("none\"") == 0)
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
result += str1;
|
|
||||||
}
|
|
||||||
|
|
||||||
//cout << strIpContentsList.length() << endl;
|
|
||||||
cout << result.toStdString() << endl;
|
|
||||||
//Debug("proxy.txt",result);
|
|
||||||
QString port = tds.at(2).toInnerXml().trimmed();
|
|
||||||
result += ("," + port);
|
|
||||||
totalResult += result;
|
|
||||||
if(i < trs.count() - 1)
|
|
||||||
totalResult += "\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
Debug(m_strFolder + "proxy.txt",totalResult);
|
|
||||||
|
|
||||||
emit finished();
|
emit finished();
|
||||||
}
|
}
|
||||||
@@ -231,8 +154,6 @@ QWebElement SCrawler::FindRight(const QWebElement _FindElement,const QString _st
|
|||||||
foreach (QWebElement element, elements)
|
foreach (QWebElement element, elements)
|
||||||
{
|
{
|
||||||
QString str = element.attribute(_strAttrib).trimmed().right(_strFind.length());
|
QString str = element.attribute(_strAttrib).trimmed().right(_strFind.length());
|
||||||
cout << "FindRight : " << str.toStdString() << endl;
|
|
||||||
cout << "FindRight right : " << _strFind.toStdString() << endl;
|
|
||||||
if (QString::compare(str,_strFind,Qt::CaseInsensitive)==0)
|
if (QString::compare(str,_strFind,Qt::CaseInsensitive)==0)
|
||||||
{
|
{
|
||||||
return element;
|
return element;
|
||||||
@@ -249,6 +170,109 @@ QWebElement SCrawler::FindLeft(const QWebElement _FindElement,const QString _str
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QString SCrawler::getIpList(const QWebElement _FindElement)
|
||||||
|
{
|
||||||
|
|
||||||
|
QString DISPLAYINLINE = "{display:inline}";
|
||||||
|
QString DISPLAYNONE = "{display:none}";
|
||||||
|
QString totalResult;
|
||||||
|
|
||||||
|
QWebElementCollection trs = _FindElement.findAll("tr");
|
||||||
|
|
||||||
|
|
||||||
|
for(int i = 1; i < trs.count(); i++)
|
||||||
|
{
|
||||||
|
QWebElementCollection tds = trs.at(i).findAll("td");
|
||||||
|
|
||||||
|
QWebElement firstStyle = trs.at(i).findFirst("style");
|
||||||
|
|
||||||
|
QString strFirstStyle = firstStyle.toInnerXml().trimmed();
|
||||||
|
|
||||||
|
QStringList disinline;
|
||||||
|
QStringList disnone;
|
||||||
|
// {display:inline} {display:none}
|
||||||
|
// Find display:inline list
|
||||||
|
// Find display:none list
|
||||||
|
QStringList strlist = strFirstStyle.split(".", QString::SkipEmptyParts);
|
||||||
|
|
||||||
|
foreach(QString str, strlist)
|
||||||
|
{
|
||||||
|
if(str.trimmed().right(DISPLAYINLINE.length()).compare(DISPLAYINLINE) == 0)
|
||||||
|
{
|
||||||
|
disinline.append(str.trimmed().left(str.trimmed().length() - DISPLAYINLINE.length()));
|
||||||
|
//cout << DISPLAYINLINE.toStdString() << " : " << str.trimmed().left(str.trimmed().length() - DISPLAYINLINE.length()).toStdString() << endl;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
disnone.append(str.trimmed().left(str.trimmed().length() - DISPLAYNONE.length()));
|
||||||
|
//cout << DISPLAYNONE.toStdString() << " : " << str.trimmed().left(str.trimmed().length() - DISPLAYNONE.length()).toStdString() << endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Change class -> display:inline
|
||||||
|
//Change class -> display:none
|
||||||
|
QString strIpContents = tds.at(1).toInnerXml();
|
||||||
|
foreach(QString str, disinline)
|
||||||
|
{
|
||||||
|
strIpContents.replace(str.trimmed(),"display: inline");
|
||||||
|
}
|
||||||
|
foreach(QString str, disnone)
|
||||||
|
{
|
||||||
|
strIpContents.replace(str.trimmed(),"display:none");
|
||||||
|
}
|
||||||
|
|
||||||
|
//cout << strIpContents.toStdString() << endl;
|
||||||
|
|
||||||
|
//Parsing contents and extracting ip and port each table row
|
||||||
|
QStringList strIpContentsList = strIpContents.split(QRegExp("[<>]"), QString::SkipEmptyParts);
|
||||||
|
QString result;
|
||||||
|
for(int j = 0; j < strIpContentsList.count(); j++)
|
||||||
|
{
|
||||||
|
QString str1 = strIpContentsList.at(j).trimmed();
|
||||||
|
|
||||||
|
if(str1.at(0) == '/')
|
||||||
|
continue;
|
||||||
|
if(str1.left(4).compare("span") == 0)
|
||||||
|
continue;
|
||||||
|
if(str1.left(3).compare("div") == 0)
|
||||||
|
continue;
|
||||||
|
if(str1.left(5).compare("style") == 0)
|
||||||
|
continue;
|
||||||
|
if(str1.mid(1,3).compare("dis") == 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if(j > 0)
|
||||||
|
{
|
||||||
|
QString str2 = strIpContentsList.at(j-1).trimmed();
|
||||||
|
if(str2.right(5).compare("none\"") == 0)
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
result += str1;
|
||||||
|
}
|
||||||
|
|
||||||
|
//cout << strIpContentsList.length() << endl;
|
||||||
|
//cout << result.toStdString() << endl;
|
||||||
|
//Debug("proxy.txt",result);
|
||||||
|
|
||||||
|
QString strport = tds.at(2).toInnerXml().trimmed();
|
||||||
|
result += ("," + strport);
|
||||||
|
totalResult += result;
|
||||||
|
if(i < trs.count() - 1)
|
||||||
|
totalResult += "\n";
|
||||||
|
}
|
||||||
|
return totalResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool SCrawler::SendIpList(QString _strIpList)
|
||||||
|
{
|
||||||
|
QStringList strListIp = _strIpList.split("\n");
|
||||||
|
|
||||||
|
|
||||||
|
return false;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
QList<QWebElement> SCrawler::FindAllMid(const QWebElement _FindElement,const QString _strElement,const QString _strAttrib,const QString _strFind, const int _strStart, const int _strLength)
|
QList<QWebElement> SCrawler::FindAllMid(const QWebElement _FindElement,const QString _strElement,const QString _strAttrib,const QString _strFind, const int _strStart, const int _strLength)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -36,8 +36,10 @@ private:
|
|||||||
QString SqlString(QString _str);
|
QString SqlString(QString _str);
|
||||||
QString GetSafeUtf(QString _strData);
|
QString GetSafeUtf(QString _strData);
|
||||||
int GetNumber(QString _str);
|
int GetNumber(QString _str);
|
||||||
|
bool SendIpList(QString _str);
|
||||||
|
|
||||||
|
|
||||||
|
QString getIpList(const QWebElement _FindElement);
|
||||||
QWebElement Find(const QWebElement _FindElement,const QString _strElement,const QString _strAttrib,const QString _strFind);
|
QWebElement Find(const QWebElement _FindElement,const QString _strElement,const QString _strAttrib,const QString _strFind);
|
||||||
QWebElement FindMid(const QWebElement _FindElement,const QString _strElement,const QString _strAttrib,const QString _strFind, const int _strStart, const int _strLength);
|
QWebElement FindMid(const QWebElement _FindElement,const QString _strElement,const QString _strAttrib,const QString _strFind, const int _strStart, const int _strLength);
|
||||||
QWebElement FindMid(const QWebElement _FindElement,const QString _strElement,const QString _strAttrib,const QString _strFind, const int _strStart);
|
QWebElement FindMid(const QWebElement _FindElement,const QString _strElement,const QString _strAttrib,const QString _strFind, const int _strStart);
|
||||||
|
|||||||
Reference in New Issue
Block a user