Proxy UI와 연동

Proxy DB 저장, Local 저장 기능

git-svn-id: svn://192.168.0.12/source@52 8346c931-da38-4b9b-9d4c-e48b93cbd075
This commit is contained in:
admin
2015-03-16 10:03:25 +00:00
parent 9c4ae16a68
commit 31b12910da
4 changed files with 88 additions and 27 deletions

View File

@@ -17,6 +17,9 @@ SCrawler::SCrawler():QObject()
{
m_page = new QWebPage;
connect(m_page, SIGNAL(loadFinished(bool)), this, SLOT(saveResult(bool)));
// p_timer = new QTimer(this);
// connect(p_timer,SIGNAL(timeout()), this, SLOT(killProcess()));
QTimer::singleShot(90000, this, SLOT(killProcess()));
}
SCrawler::~SCrawler()
@@ -32,9 +35,15 @@ void SCrawler::load(QStringList _strlistArgv)
if(_strlistArgv.length() > 1)
m_strFolder = _strlistArgv.at(1) + "\\";
m_strFolder = _strlistArgv.at(1).trimmed() + "\\";
if(_strlistArgv.length() > 2)
m_strLocation = _strlistArgv.at(2).trimmed();
else
m_strLocation = "local";
m_page->currentFrame()->load(url);
}
void SCrawler::UpdateError(QString _strError)
@@ -60,9 +69,19 @@ void SCrawler::saveResult(bool ok)
//SendIpList(strIpList);
Debug(m_strFolder + "proxy.txt",strIpList);
if((m_strLocation.compare("local") == 0) || (m_strLocation.compare("both") == 0))
{
if(Debug(m_strFolder + "proxy.txt",strIpList) == false)
return;
}
if((m_strLocation.compare("db") == 0) || (m_strLocation.compare("both") == 0))
{
if(SendIpList(strIpList) == false)
return;
}
emit finished();
cout << endl << "ok";
}
int SCrawler::GetNumber(QString _str)
@@ -76,16 +95,21 @@ int SCrawler::GetNumber(QString _str)
return strNumber.toInt();
}
void SCrawler::Debug(QString _strFilename,QString _strData)
bool SCrawler::Debug(QString _strFilename,QString _strData)
{
QFile file(_strFilename);
QFile::remove(_strFilename);
if (!file.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Append))
{
// if (!file.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate))
return;
cout << "savefail" << endl;
emit finished();
return false;
}
QTextStream out(&file);
out << _strData;
file.close();
return true;
}
QString SCrawler::SqlString(QString _str)
@@ -267,11 +291,50 @@ QString SCrawler::getIpList(const QWebElement _FindElement)
bool SCrawler::SendIpList(QString _strIpList)
{
QStringList strListIp = _strIpList.split("\n");
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..." << endl;
cout << "dbcfail";
emit finished();
return false;
}
return false;
QSqlQuery sql;
//QString strQuery = "truncate table Proxy";
QString strQuery = "delete from Proxy";
QString strUtf8(strQuery.toUtf8());
if (sql.exec(strUtf8) == false)
{
cout << "error : " << sql.lastError().text().toStdString();
cout << endl << "dbdfail";
//emit finished();
//return;
}
QStringList strListIpList = _strIpList.split('\n', QString::SkipEmptyParts);
foreach(QString str, strListIpList)
{
strQuery = "insert into Proxy set Proxy='";
strQuery += str.split(',').at(0).trimmed();
strQuery += "', Port=";
strQuery += str.split(',').at(1).trimmed();
strUtf8 = strQuery.toUtf8();
if (sql.exec(strUtf8) == false)
{
cout << "error : " << sql.lastError().text().toStdString();
cout << endl << "dbufail";
return false;
}
}
return true;
}
QList<QWebElement> SCrawler::FindAllMid(const QWebElement _FindElement,const QString _strElement,const QString _strAttrib,const QString _strFind, const int _strStart, const int _strLength)
@@ -289,3 +352,9 @@ QList<QWebElement> SCrawler::FindAllMid(const QWebElement _FindElement,const QSt
}
return returnElements;
}
void SCrawler::killProcess()
{
cout << endl << "timeout";
emit finished();
}