navernews 댓글 가져오기 수정
json형식 뒤에 이상한 문자들이 붙어있어서 오류를 일으킴 git-svn-id: svn://192.168.0.12/source@218 8346c931-da38-4b9b-9d4c-e48b93cbd075
This commit is contained in:
@@ -176,7 +176,7 @@ void SCrawler::saveResultNaverNews()
|
||||
if (strlike.isEmpty() == false) strData += "\r\nlike(" + QString::number(strlike.toInt()) + ")";
|
||||
else
|
||||
{
|
||||
Debug("out.html",m_page->mainFrame()->toHtml());
|
||||
//Debug("out.html",m_page->mainFrame()->toHtml());
|
||||
}
|
||||
|
||||
element = Find(m_page->mainFrame()->documentElement(),"div","class","press_logo");
|
||||
|
||||
@@ -4,6 +4,9 @@
|
||||
#include <QJsonArray>
|
||||
#include <QHostInfo>
|
||||
#include <iostream>
|
||||
#include <QFile>
|
||||
#include <QTextStream>
|
||||
|
||||
|
||||
using namespace std;
|
||||
|
||||
@@ -73,11 +76,21 @@ void SReplyGetManage::NaverNewsRun()
|
||||
{
|
||||
byArray += socket.readAll();
|
||||
}
|
||||
|
||||
/*
|
||||
{
|
||||
QFile raw("c:\\data\\rawnews.json");
|
||||
raw.open(QFile::WriteOnly | QFile::Text);
|
||||
QTextStream in(&raw);
|
||||
in << QString(byArray);
|
||||
raw.close();
|
||||
}
|
||||
*/
|
||||
int index = byArray.indexOf("{");
|
||||
byArray=byArray.mid(index-2);
|
||||
bool bFlag = true;
|
||||
|
||||
QString strOut;
|
||||
|
||||
while(bFlag)
|
||||
{
|
||||
strOut += byArray.left(8188);
|
||||
@@ -88,7 +101,15 @@ void SReplyGetManage::NaverNewsRun()
|
||||
strOut += byArray;
|
||||
}
|
||||
}
|
||||
strOut = strOut.replace("\r\n","").replace("\n","");
|
||||
|
||||
strOut = strOut.replace("\r\n","").replace("\n","");
|
||||
{
|
||||
QRegExp re("\\}\\}[\\w\\s]*$");
|
||||
|
||||
strOut = strOut.replace(re,"}}");
|
||||
}
|
||||
|
||||
|
||||
QJsonParseError error;
|
||||
QJsonDocument d = QJsonDocument::fromJson(strOut.toUtf8(),&error);
|
||||
if (error.error != 0)
|
||||
@@ -103,6 +124,7 @@ void SReplyGetManage::NaverNewsRun()
|
||||
{
|
||||
QJsonObject obj = value.toObject();
|
||||
pReply[nCount].m_nReplyReplyCount = obj["replyCount"].toInt();
|
||||
//qDebug() << "m_nReplyReply" << pReply[nCount].m_nReplyReplyCount;
|
||||
int i= E_REPLY_USER_ID;
|
||||
while (i < E_REPLY_MAX)
|
||||
{
|
||||
@@ -140,6 +162,8 @@ void SReplyGetManage::NaverNewsRun()
|
||||
nCount++;
|
||||
}
|
||||
m_pool->waitForDone();
|
||||
// qDebug() << "m_nTotal = " << m_nTotal;
|
||||
|
||||
for (int i = 0; i < m_nTotal ; i++)
|
||||
{
|
||||
m_pData->setData(m_pData->GetDate(pReply[i].m_strReplyData[E_REPLY_DATE]), SCrawlerData::ARTICLE_DATE);
|
||||
@@ -147,6 +171,7 @@ void SReplyGetManage::NaverNewsRun()
|
||||
m_pData->setData(m_pData->SqlString(m_pData->GetSafeUtf(pReply[i].m_strReplyData[E_REPLY_USER_NICKNAME])), SCrawlerData::ARTICLE_NICKNAME);
|
||||
m_pData->setData(m_pData->SqlString(m_pData->GetSafeUtf(pReply[i].m_strReplyData[E_REPLY_USER_ID])), SCrawlerData::ARTICLE_ID);
|
||||
m_pData->setData(m_pData->SqlString(m_pData->GetSafeUtf(pReply[i].m_strReplyReply.join("\r\n"))), SCrawlerData::ETC);
|
||||
m_pData->setData(QString::number(i), SCrawlerData::ARTICLE_ORDER);
|
||||
m_pData->sendDB();
|
||||
}
|
||||
delete [] pReply;
|
||||
|
||||
@@ -53,7 +53,6 @@ void SRunnable::RunNaverNews()
|
||||
{
|
||||
byArray += socket.readAll();
|
||||
}
|
||||
|
||||
QJsonDocument d;
|
||||
{
|
||||
QJsonParseError error;
|
||||
@@ -71,13 +70,22 @@ void SRunnable::RunNaverNews()
|
||||
strOut += byArray;
|
||||
}
|
||||
}
|
||||
|
||||
strOut = strOut.replace("\r\n","").replace("\n","");
|
||||
|
||||
{
|
||||
QRegExp re("\\}\\}[\\w\\s]*$");
|
||||
strOut = strOut.replace(re,"}}");
|
||||
}
|
||||
|
||||
|
||||
if (strOut.length() <= 0 ) return;
|
||||
d = QJsonDocument::fromJson(strOut.trimmed().toUtf8(),&error);
|
||||
if (error.error != 0)
|
||||
{
|
||||
qDebug() << error.errorString();
|
||||
Debug("reply.json",strOut);
|
||||
socket.close();
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user