#ifndef SCRAWLER_H
#define SCRAWLER_H

#include <QtWebKitWidgets>
#include "scrawlerdata.h"
class SCrawler : public QObject
{
    Q_OBJECT
public:
    enum E_SELECT
    {
        E_NAVER_CAFE_LIST = 0,
        E_NAVER_CAFE_DATA,
        E_NAVER_BLOG_LIST,
        E_NAVER_BLOG_BODY,
        E_NAVER_BLOG_REPLY,
        E_DAUM_CAFE_LIST,
        E_DAUM_CAFE_DATA,
        E_DAUM_BLOG_LIST,
        E_DAUM_BLOG_BODY,
        E_DAUM_BLOG_REPLY,
        E_NAVER_NEWS_LIST,
        E_NAVER_NEWS_DATA,
        E_NAVER_NEWS_REPLY,
    };
public:
    SCrawler();
    ~SCrawler();
    void load(QStringList _strlistArgv);
    void saveFile();
    static void Debug(QString _strFilename,QString _strData);
signals:
    void finished();
private slots:
    void saveResult(bool ok);
    void reloadPage();
private:
    int m_nSelect;        
    QString m_strReper;
    QString m_strKeywordID;

    SCrawlerData bodydata;

    QWebPage *m_page;
    QString m_strFile;    
    QString m_strUrl;
    QString m_strTable;
    QString m_strIp;
    bool m_bUse;
    bool m_bLast;
    bool m_bError;
    bool m_bNothing;
    QString m_strProxyIP;
    int m_nProxyPort;
    int m_nRetryCount;
    QString SqlString(QString _str);
    QString GetSafeUtf(QString _strData);
    void saveFrameList(QWebFrame *frame);
    void saveFrameCafeList(QWebFrame *frame);
    bool saveFrameUrl(QWebFrame *frame);
    void saveFrameComment(QWebFrame *frame);    
    void saveFrameCafeUrl(QWebFrame *frame);
    void saveFrameDaumBlogList(QWebFrame *frame);
    void saveFrameDaumCafeList(QWebFrame *frame);
    void saveFrameDaumBlogUrl(QWebFrame *frame);
    void saveFrameDaumBlogComment(QWebFrame *frame);
    void saveFrameDaumCafeUrl(QWebFrame *frame);
    void saveFrameNewsList(QWebFrame *frame);
    void saveFrameNewsUrl(QWebFrame *frame);
    bool saveFrameNewsComment(QWebFrame *frame);

    int GetNumber(QString _str);
    bool getProxyList(QString &_str);
    void setProxy();
    void deleteProxy();

    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);
    QWebElement FindRight(const QWebElement _FindElement,const QString _strElement,const QString _strAttrib,const QString _strFind);
    QWebElement FindLeft(const QWebElement _FindElement,const QString _strElement,const QString _strAttrib,const QString _strFind);
    QList<QWebElement> FindAllMid(const QWebElement _FindElement,const QString _strElement,const QString _strAttrib,const QString _strFind, const int _strStart, const int _strLength);
    QWebElementCollection Finds(const QWebElement _FindElement,const QString _strElement,const QString _strAttrib,const QString _strFind);
    void UpdateError(QString _strError);
};


#endif // SCRAWLER_H
