소스코드 정리

git-svn-id: svn://192.168.0.12/source@50 8346c931-da38-4b9b-9d4c-e48b93cbd075
This commit is contained in:
admin
2015-03-16 03:10:10 +00:00
parent dd597f0c5b
commit 8fad270ba8
3 changed files with 120 additions and 82 deletions

View File

@@ -17,6 +17,18 @@ int main(int argc, char *argv[])
a.setApplicationName(QString("Chrome"));
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;
QObject::connect(process, SIGNAL(finished()), QApplication::instance(), SLOT(quit()));

View File

@@ -54,90 +54,13 @@ void SCrawler::saveResult(bool ok)
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("filtered.html", p_parse.toInnerXml());
QWebElementCollection trs = p_parse.findAll("tr");
QString DISPLAYINLINE = "{display:inline}";
QString DISPLAYNONE = "{display:none}";
QString totalResult;
//SendIpList(strIpList);
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}
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);
Debug(m_strFolder + "proxy.txt",strIpList);
emit finished();
}
@@ -231,8 +154,6 @@ QWebElement SCrawler::FindRight(const QWebElement _FindElement,const QString _st
foreach (QWebElement element, elements)
{
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)
{
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)
{

View File

@@ -36,8 +36,10 @@ private:
QString SqlString(QString _str);
QString GetSafeUtf(QString _strData);
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 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);