虚静

 
 

常用链接

  • 我的随笔
  • 我的评论
  • 我参与的随笔

留言簿

  • 给我留言
  • 查看公开留言
  • 查看私人留言

随笔档案

  • 2008年10月 (1)
  • 2008年9月 (2)

文章档案

  • 2008年9月 (4)

搜索

  •  

最新评论

阅读排行榜

  • 1. 一个网页提取信息和注册到另一个网页的小程序(23)
  • 2. 从亨者提取企业黄页信息的任务(17)
  • 3. 前晚下雨了(13)

评论排行榜

  • 1. 从亨者提取企业黄页信息的任务(0)
  • 2. 前晚下雨了(0)
  • 3. 一个网页提取信息和注册到另一个网页的小程序(0)

Powered by: 博客园
模板提供:沪江博客
C++博客 | 首页 | 发新随笔 | 发新文章 | 联系 | 聚合 | 管理

2008年10月16日

一个网页提取信息和注册到另一个网页的小程序
CCompanyInformationView::CCompanyInformationView()
{
}

CCompanyInformationView::~CCompanyInformationView()
{
}


BEGIN_MESSAGE_MAP(CCompanyInformationView, CWnd)
    //{{AFX_MSG_MAP(CCompanyInformationView)
    ON_WM_SIZE()
    ON_WM_CREATE()
    ON_WM_DESTROY()   
    ON_WM_TIMER()
    ON_COMMAND(idcCollectInformation,OnCollectInformation)
    ON_COMMAND(idcSaveInformation,OnSaveInformation)
    ON_COMMAND(idcPauseCollect,OnPauseCollect)
    ON_COMMAND(idcRegisterQiYe,OnRegisterQiYe)
    //}}AFX_MSG_MAP
END_MESSAGE_MAP()


/////////////////////////////////////////////////////////////////////////////
// CCompanyInformationView message handlers

void CCompanyInformationView::OnSize(UINT nType, int cx, int cy)
{
    CWnd::OnSize(nType, cx, cy);
    m_layout.OnSize(0,cx,cy);
}

BOOL CCompanyInformationView::PreCreateWindow(CREATESTRUCT& cs)
{
    if (!CWnd::PreCreateWindow(cs))
        return FALSE;

    cs.dwExStyle &= ~WS_EX_CLIENTEDGE;
    cs.style &= ~WS_BORDER;
    cs.lpszClass = AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW|CS_DBLCLKS,
        ::LoadCursor(NULL, IDC_ARROW), NULL, NULL);
    return true;
}

int CCompanyInformationView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
    if (CWnd::OnCreate(lpCreateStruct) == -1)
        return -1;

    DWORD dwStyle=WS_CHILD|WS_VISIBLE;
    CRect rect;

    CString strPath,strImagePath;
    GetModulePath(strPath);
    strImagePath=strPath+"images\\";

    m_bar.Create(rect,this,0,WS_CHILD|WS_VISIBLE);
    rect.right=100;   
    dwStyle=WS_CHILD | WS_VISIBLE | WS_GROUP | WS_TABSTOP;
    CButtonST *pButton;
    CLayoutRow *pRow = m_bar.AddRow(20);

    m_bar.AddLabel(pRow,"输入地区名称:",0,110);

    CEdit * pEdit=new CEdit;
    pEdit->Create(WS_VISIBLE|WS_CHILD|WS_TABSTOP|WS_BORDER,rect,&m_bar,idcArea);
    pRow->AddControl(pEdit,190);


    pButton = new CButtonST;
    pButton->Create("提取公司信息",dwStyle,rect,&m_bar,idcCollectInformation);   
    pRow->AddControl(pButton,110);
    pButton->SetImage(strImagePath+"item.gif",0xffffff);

    pButton = new CButtonST;
    pButton->Create("保存公司信息",dwStyle,rect,&m_bar,idcSaveInformation);   
    pRow->AddControl(pButton,110);
    pButton->SetImage(strImagePath+"item.gif",0xffffff);

    pButton = new CButtonST;
    pButton->Create("暂停提取信息",dwStyle,rect,&m_bar,idcPauseCollect);   
    pRow->AddControl(pButton,110);
    pButton->SetImage(strImagePath+"item.gif",0xffffff);

    pButton = new CButtonST;
    pButton->Create("注册企业信息",dwStyle,rect,&m_bar,idcRegisterQiYe);   
    pRow->AddControl(pButton,110);
    pButton->SetImage(strImagePath+"item.gif",0xffffff);


    m_bar.AddRow(5);//spacing    


    dwStyle = WS_CHILD | WS_TABSTOP | WS_VISIBLE;
    m_grid.Create(rect,this,idcGrid,dwStyle);

    m_grid.SetFixedRowCount(1);
    m_grid.SetFixedColumnCount(1);   
    m_grid.SetFixedBkColor (0xb0c4de);
    m_grid.SetEditable(false);
    m_grid.SetListMode();
    m_qdbgrid.SetTable("CompanyInformation");
    m_qdbgrid.AttachGrid(&m_grid);
    m_qdbgrid.AddField("KeyId","编号");
    m_qdbgrid.AddField("Customer","公司名称");
    m_qdbgrid.AddField("Address","公司地址");
    m_qdbgrid.AddField("PostCode","邮政编码");
    m_qdbgrid.AddField("Homepage","网址");
    //m_qdbgrid.AddField("Email","邮箱");   
    m_qdbgrid.AddField("Contact","联系人");
    m_qdbgrid.AddField("Area","区号");
    m_qdbgrid.AddField("Phone","座机号");
    m_qdbgrid.AddField("Fax","传真");
    m_qdbgrid.AddField("Mobile","手机号码");
    m_qdbgrid.AddField("Province","省");
    m_qdbgrid.AddField("City","市");
    m_qdbgrid.AddField("Trade","主营业务");
    m_qdbgrid.AddField("Abstract","公司简介");
   
    m_qdbgrid.SetOrder(" order by keyid desc ");

    m_layout.m_pOwnerWnd = this;
    m_layout.m_iRowSpace =0;
    pRow = m_layout.AddRow(24);  pRow->m_iCellSpace =0;
    pRow->AddStatic(&m_bar,100,0);
    pRow = m_layout.AddRow(100,0);  pRow->m_iCellSpace =0;
    pRow->AddStatic(&m_grid,100,0);

    GetClientRect(&rect);
    m_layout.OnSize (0,rect.Width (),rect.Height());   

    //m_qdbgrid.Retrieve(m_pDB);
    m_qdbgrid.BuildHeader();
    //CGridPosProfile::Load(&m_grid,"CCompanyInformationView");
    return 0;
}

void CCompanyInformationView::OnDestroy()
{
    CGridPosProfile::Save(&m_grid,"CCompanyInformationView");   
   
    CWnd::OnDestroy();   
}


//--------------------------------------------------------

//  右键与双击
//---------------------------------------------------------
BOOL CCompanyInformationView::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
{
    NM_GRIDVIEW * nm=(NM_GRIDVIEW *)lParam;
    if(wParam==idcGrid){
        if(nm->hdr.code==NM_DBLCLK){
            PostMessage(WM_COMMAND,idcGrid,BN_CLICKED);
            return true;
        }
        if(nm->hdr.code==NM_RCLICK){
            PopupMenu();
        }
        //GVN_SELCHANGED
    }       
    return CWnd::OnNotify(wParam, lParam, pResult);
}

void CCompanyInformationView::PopupMenu(){
    POINT pt;
    GetCursorPos(&pt);
    BCMenu menu;
    menu.CreatePopupMenu();
    menu.AppendMenu(MF_POPUP,idcCollectInformation,"添加");
    menu.AppendMenu(MF_POPUP,idcSaveInformation,"编辑");
   
    DWORD dwRetValue = menu.TrackPopupMenu(TPM_LEFTALIGN | TPM_LEFTBUTTON | TPM_RIGHTBUTTON | TPM_NONOTIFY | TPM_RETURNCMD, pt.x, pt.y, this, NULL);
    PostMessage(WM_COMMAND, MAKEWPARAM(dwRetValue, 0), (LPARAM)NULL);
}
//提取公司信息
void CCompanyInformationView::OnCollectInformation()
{   
    CString str ;
    m_bar.GetDlgItemText(idcArea,str);
    if(str.IsEmpty())
    {
        MessageBox("请输入地区名称");
        return;
    }
    CString strURL="http://www.diytrade.com/china/2/companies/0-s-c-1.html?qs=";
    CWTString wts;
    m_bStatus=true;
    m_bPause=true;
    ant.m_iStatus=0;
    if(m_strLinkArray.GetSize()>=1)
        m_strLinkArray.RemoveAll();
    m_grid.DeleteAllItems();
    m_qdbgrid.BuildHeader();
    m_grid.Invalidate();


    strURL+=wts.URLEncode(wts.GB2312ToUTF8(str));
    strURL+="&qc=comp&ns=1";
    WriteFileText("E:\\kankan.txt",strURL);
   
    ant.m_strMethod="GET";
    ant.m_strURL=strURL;
    ant.Start();
    SetTimer(1,10,NULL);
   
}



//取一个页面的二十个链接和下一页的链接(包括主页和所有的下一页)
void CCompanyInformationView::GetPageLink()
{

    m_TagNextPage=false;
    CWTString wts;
    CString str ;

    if(!m_bPause) return;

    str=wts.UTF8ToGB2312(ant.m_strBody);
    CString strPath;
   
    reader.SetHtml(str);
    LPCTSTR lpTag;
    CString strValue,strName,strInside;
    for(;;)
    {
        if(m_bPause==false) return;
        lpTag=reader.GetNextTag();
        strName=reader.GetTagName(lpTag);
        if(strName.Compare("/body")==0) break;
        if(strName!="a")  continue;
        strValue=reader.GetInnerHtml(lpTag);//找出下一页的链接
        if(strValue.Compare("下一页")==0)
        {
            strValue=reader.GetTagAttribute(lpTag,"href");
            str="http://www.diytrade.com"+strValue;
            m_strLinkArray.Add(str);
            m_TagNextPage=true;
        }
        strValue=reader.GetTagAttribute(lpTag,"href");
        if(strValue.Find("/china/2/manufacturers/")<0) continue;
        lpTag=reader.GetNextTag();
        strName=reader.GetTagName(lpTag);
        if(strName!="b") continue;
        str="http://www.diytrade.com"+strValue;
        m_strLinkArray.Add(str);
           
    }
    /*for(int i=0 ; i<m_strLinkArray.GetSize() ; i++)
    {
        str.Format("%d",i);
        MessageBox(m_strLinkArray.GetAt(i)+"\r\n"+str);
    }*/
    ant.m_strBody="";
    ant.m_strMethod="GET";
    ant.m_strURL=m_strLinkArray.GetAt(0);
    m_strLinkArray.RemoveAt(0);
    SetTimer(1,10,NULL);
    ant.Start();

}
//----------------------------------
//数据库操作将某个企业基本信息保存到数据库
void CCompanyInformationView::SaveData()
{

    CWTString wts;
    CString str;

    CString strURL;
    CString strProvince,strCity;
    int nRowId=0;
    int at1;
    int tot=ant.m_strBody.GetLength();
    CString strRowId;
    if(tot>19000)
    {str.Format("%d",tot);
       
        nRowId=m_grid.InsertRow("gaga");
        if(nRowId==0) nRowId=m_grid.InsertRow("gaga");
        strRowId.Format("%d",nRowId);
        m_grid.SetItemText(nRowId,0,strRowId);

        str=wts.UTF8ToGB2312(ant.m_strBody);
        reader.SetHtml(str);
        LPCTSTR lpTag;
        CString strName, strInside,strValue;
        int ntag;
   
        for(ntag=0;;)

        {   

            lpTag=reader.GetNextTag();
            strName=reader.GetTagName(lpTag);
            if(strName.Compare("td")!=0)  continue;
            if(ntag==0)
            {
                strValue=reader.GetTagAttribute(lpTag,"class");
                if(strValue.Compare("comPageDesc")==0)
                {
                    strInside=reader.GetInnerHtml(lpTag);
                   
                    strInside.Replace(" ","");
                    at1=strInside.Find("</a>");
                    if(at1>=0)
                    {
                        CString strPlace="";
                        strPlace=strInside.Mid(0,at1+4);
                        strInside.Replace(strPlace,"");                       
                    }
                    strInside.TrimLeft();
                    strInside.TrimRight();
                    strInside.Replace("<br/>","");
               
                    m_grid.SetItemText(nRowId,13,strInside);
                    ntag=1;
                }
               
            }
            strValue=reader.GetTagAttribute(lpTag,"align");
            str=reader.GetInnerHtml(lpTag);
            if(str.Find("免责声明:")>=0)  break;
            if(strValue.Compare("right")!=0)  continue;

            strValue=reader.GetInnerHtml(lpTag);
            if(strValue.Find("<b>公司名称︰</b>")>=0)
            {
                ntag=1;//不再查找公司简介
                for(;;)
                {                   
                    lpTag=reader.GetNextTag();
                    strName=reader.GetTagName(lpTag);
                    if(strName.Compare("td")==0)
                        break;
                }
                strValue=reader.GetInnerHtml(lpTag);
                if(!strValue.IsEmpty())
                {
                    int index=dbGetLastKeyId(m_pDB,"CompanyInformation")+1;
               
                    m_grid.SetItemText(nRowId,1,strValue);
                }
                else break;
            }
            else if(strValue.Find("<b>国家/地区︰</b>")>=0)
            {
                for(;;)
                {                   
                    lpTag=reader.GetNextTag();
                    strName=reader.GetTagName(lpTag);
                    if(strName.Compare("h3")==0)
                        break;
                }
                strValue=reader.GetInnerHtml(lpTag);
                if(strValue.IsEmpty())  continue;
                strValue.TrimLeft();
                strValue.TrimRight();
                at1=strValue.Find("省");
                if(at1>=0)
                {
                   
                    m_grid.SetItemText(nRowId,10,strValue.Mid(0,at1+2));
                   
                    m_grid.SetItemText(nRowId,11,strValue.Mid(at1+2,strValue.GetLength()-at1));
                }
                else
                {
                   
                    m_grid.SetItemText(nRowId,11,strValue);
                }
            }
            else if(strValue.Find("<b>公司地址︰</b>")>=0)
            {
                for(;;)
                {                   
                    lpTag=reader.GetNextTag();
                    strName=reader.GetTagName(lpTag);
                    if(strName.Compare("td")==0)
                        break;
                }
                strValue=reader.GetInnerHtml(lpTag);
                if(strValue.IsEmpty())  continue;
                strValue.TrimLeft();
                strValue.TrimRight();
           
                m_grid.SetItemText(nRowId,2,strValue);
   
            }
            else if(strValue.Find("邮政编码︰")>=0)
            {
                for(;;)
                {                   
                    lpTag=reader.GetNextTag();
                    strName=reader.GetTagName(lpTag);
                    if(strName.Compare("td")==0)
                        break;
                }
                strValue=reader.GetInnerHtml(lpTag);
                if(strValue.IsEmpty())  continue;
                strValue.TrimLeft();
                strValue.TrimRight();
           
                if(strValue.GetLength()==6)
                m_grid.SetItemText(nRowId,3,strValue);
            }
            else if(strValue.Find("<b>公司电话︰</b>")>=0)
            {
                for(;;)
                {                   
                    lpTag=reader.GetNextTag();
                    strName=reader.GetTagName(lpTag);
                    if(strName.Compare("td")==0)
                        break;
                }
                strValue=reader.GetInnerHtml(lpTag);
                if(strValue.IsEmpty())  continue;
                strValue.TrimLeft();
                strValue.TrimRight();
           
                //////////改写电话
               
                if(strValue.Find("86-")>=0)
                    strValue.Replace("86-","");
                at1=strValue.Find("-");
                str=strValue.Mid(0,at1);
                if(at1<4&&strValue.Mid(0,1)!="0")
                    strProvince="0"+str;
                else
                    strProvince=str;
                strCity=strValue.Mid(at1+1,strValue.GetLength()-at1);               
                /////////
                if(strProvince.Compare("0")==0)  strProvince="";
                m_grid.SetItemText(nRowId,6,strProvince);
                at1=strCity.Find(" ");
                if(at1>=0)
                {               
                    str=strCity.Mid(at1);
                    strCity.Replace(str,"");
                }
                if(strCity.GetLength()<7||strCity.GetLength()>8)
                    strCity="";
                m_grid.SetItemText(nRowId,7,strCity);
            }
            else if(strValue.Find("<b>公司传真︰</b>")>=0)
            {
                for(;;)
                {                   
                    lpTag=reader.GetNextTag();
                    strName=reader.GetTagName(lpTag);
                    if(strName.Compare("td")==0)
                        break;
                }
                strValue=reader.GetInnerHtml(lpTag);
                if(strValue.IsEmpty())  continue;
                strValue.TrimLeft();
                strValue.TrimRight();
           
                //////////改写传真
               
                if(strValue.Find("86-")>=0)
                    strValue.Replace("86-","");
                at1=strValue.Find("-");
                str=strValue.Mid(0,at1);
               
                strCity=strValue.Mid(at1+1,strValue.GetLength()-at1);               
                /////////
                m_grid.SetItemText(nRowId,6,strProvince);
                m_grid.SetItemText(nRowId,8,strCity);
            }
            else if(strValue.Find("<b>联系人︰</b>")>=0)
            {
                for(;;)
                {                   
                    lpTag=reader.GetNextTag();
                    strName=reader.GetTagName(lpTag);
                    if(strName.Compare("td")==0)
                        break;
                }
                strValue=reader.GetInnerHtml(lpTag);
                if(strValue.IsEmpty())  continue;
                strValue.TrimLeft();
                strValue.TrimRight();
           
                m_grid.SetItemText(nRowId,5,strValue);
            }
            else if(strValue.Find("<b>联系电话︰</b>")>=0)
            {
                for(;;)
                {                   
                    lpTag=reader.GetNextTag();
                    strName=reader.GetTagName(lpTag);
                    if(strName.Compare("td")==0)
                        break;
                }
                strValue=reader.GetInnerHtml(lpTag);
                if(strValue.IsEmpty())  continue;
                strValue.TrimLeft();
                strValue.TrimRight();
               
                if((strValue.Find("-")>=0)||(strValue.GetLength()!=11)||(strValue.Mid(0,1)!="1"))
                    strValue="";
                m_grid.SetItemText(nRowId,9,strValue);
            }
            else if(strValue.Find("<b>主营行业︰</b>")>=0)
            {
                for(;;)
                {                   
                    lpTag=reader.GetNextTag();
                    strName=reader.GetTagName(lpTag);
                    if(strName.Compare("h3")==0)
                        break;
                }
                strValue=reader.GetInnerHtml(lpTag);
                if(strValue.IsEmpty())  continue;
                strValue.TrimLeft();
                strValue.TrimRight();
               
                m_grid.SetItemText(nRowId,12,strValue);
            }
            else if(strValue.Find("<b>公司网址︰</b>")>=0)
            {
                for(;;)
                {                   
                    lpTag=reader.GetNextTag();
                    strName=reader.GetTagName(lpTag);
                    if(strName=="a")
                        break;
                }
                strValue=reader.GetTagAttribute(lpTag,"href");
                if(strValue.IsEmpty())  continue;
           
                m_grid.SetItemText(nRowId,4,strValue);
                break;
            }
        }
    }   
    m_grid.Invalidate();
    m_grid.UpdateWindow();
   
   
    ant.m_strMethod="GET";
    if(m_strLinkArray.GetSize()>=1)
    {
        ant.m_strURL=m_strLinkArray.GetAt(0);
        m_strLinkArray.RemoveAt(0);
        SetTimer(1,10,NULL);
        ant.Start();
    }
    else
    {
        MessageBox("查询完毕!");
        //m_strLinkArray.RemoveAll();
        return;
    }
}

//保存公司信息
void CCompanyInformationView::OnSaveInformation()
{
    if(m_bStatus==false)
    {
        MessageBox("请勿重复保存公司数据!");
        return;
    }
    CString strValue;
    CSQLInsert  sql;
    CStringArray  strArray;
    strArray.SetSize(13);
    strArray.SetAt(0,"Customer");
    strArray.SetAt(1,"Address");
    strArray.SetAt(2,"PostCode");
    strArray.SetAt(3,"Homepage");
    strArray.SetAt(4,"Contact");
    strArray.SetAt(5,"Area");
    strArray.SetAt(6,"Phone");
    strArray.SetAt(7,"Fax");
    strArray.SetAt(8,"Mobile");
    strArray.SetAt(9,"Province");
    strArray.SetAt(10,"City");
    strArray.SetAt(11,"Trade");   
    strArray.SetAt(12,"Abstract");
    int RecordNum=m_grid.GetRowCount();
    for(int index=1 ; index<RecordNum ; index++ )
    {
        sql.DeleteContents();
        sql.SetTableName("companyinformation");
        for(int nValue=1 ; nValue<=13 ; nValue++)
        {
            strValue=m_grid.GetItemText(index,nValue);
            if(!strValue.IsEmpty())
            {
                sql.SetFieldText(strArray.GetAt(nValue-1),strValue);
            }
        }
        CString strSQL=sql.GetSQL();
        if(m_pDB->Execute(strSQL)<1)
        {
            //MessageBox(m_pDB->m_strError+"\r\n"+strSQL);
            continue;
        }

    }
    MessageBox("公司信息已保存到数据库!");
    m_bStatus=false;
   
}
//-------------

void CCompanyInformationView::OnPauseCollect()
{
    m_bPause=false;
    if(ant.IsRunning())
    ant.Abort();
       
}
////注册到企业信息网
void CCompanyInformationView::OnRegisterQiYe()
{
    m_bPause=true;
    ant.m_iStatus=0;
    nRowId=m_grid.GetRowCount();
    nRowId--;
    DoRegister();
   
}
void CCompanyInformationView::DoRegister()
{
   
    //ant.m_strBody="";
    CString strForm,str,strMsg;
    CWTString wts;   
   
    strForm="l=http%3A%2F%2Fwww%2Eqiyexinxi%2Enet";

    str = m_grid.GetItemText(nRowId,1);
    strForm+= "&t=";
    strForm+= wts.URLEncode(str);

    str = m_grid.GetItemText(nRowId,6);
    str+=m_grid.GetItemText(nRowId,7);
    strForm+= "&Phone=";
    strForm+= wts.URLEncode(str);

    str = m_grid.GetItemText(nRowId,9);
    strForm+= "&Mobile=";
    strForm+= wts.URLEncode(str);

    strForm+="&Email=";

    str = m_grid.GetItemText(nRowId,5);
    strForm+= "&Contact=";
    strForm+= wts.URLEncode(str);
   
    str = m_grid.GetItemText(nRowId,2);
    strForm+= "&Address=";
    strForm+= wts.URLEncode(str);
   
    str = m_grid.GetItemText(nRowId,3);
    strForm+="&PostCode=";
    strForm+= wts.URLEncode(str);
   
    strForm+="&QQ=&MSN=";
   
    str = m_grid.GetItemText(nRowId,4);
    strForm+= "&Homepage=";
    strForm+= wts.URLEncode(str);

    str = m_grid.GetItemText(nRowId,12);
    strForm+= "&Business=";
    strForm+= wts.URLEncode(str);

    str = m_grid.GetItemText(nRowId,13);
    strForm+= "&Abstract=";
    strForm+= wts.URLEncode(str);
   
   
    strForm+= "&l=http%3A%2F%2Fwww%2Eqiyexinxi%2Enet";

    strForm+= "&submit=1&x=38&y=8";

    ant.m_strMethod="POST";
    ant.m_strOptional = strForm;
    ant.m_strContentType="application/x-www-form-urlencoded";
    ant.m_strURL="http://www.qiyexinxi.net/main/yp_reg.asp";
    //WriteFileText("E:\\kan.txt",ant.m_strOptional);
    //MessageBox(ant.m_strOptional);
    SetTimer(2,100,NULL);
    int re=ant.Start();

}
///////////////////////////
void CCompanyInformationView::OnTimer(UINT nIDEvent)
{

    switch(nIDEvent)
    {
        case 1:
        if(!m_bPause)
        {
            KillTimer(1);
            return ;
        }
        if(ant.m_iStatus==200)
        {
            ant.m_iStatus=0;
            KillTimer(1);
            if(m_strLinkArray.GetSize()==0&&m_TagNextPage)
            GetPageLink();
           
            else
            SaveData();   
        }   
        break;

        case 2:
        if(!m_bPause)
        {
            KillTimer(2);
            return ;
        }
               
        if(ant.m_iStatus=200)
        {
            ant.m_iStatus=0;
            KillTimer(2);
            //CWTString wts;
            //WriteFileText("E:\\kankan.txt",ant.m_strBody);
            //MessageBox(ant.m_strBody);
            if(ant.m_strBody.Find("注册成功")>=0)
                MessageBox("注册成功");
            if(ant.m_strBody.Find("请不要重复注册")>=0)
                MessageBox("已经注册过");
           
            nRowId--;
            if(nRowId>0)
            DoRegister();
            else
            {
                MessageBox("所有公司注册完毕");
                return;
            }
        }
        break ;
    }
}
posted @ 2008-10-16 16:18 独履_天涯 阅读(23) | 评论 (0) | 编辑 收藏
 

2008年9月26日

前晚下雨了
   前天晚上去理工看书,出来时竟然下雨了,门口聚了好多理工的同学,我想在理工看到那么晚的也就我一

个校外人吧。
   开始雨不大,本来想跑回去,可是怕把书湿了(因为借的是同事的),才几分钟,雨就变很急了,渐

渐的,好多人打电话让同学送伞,而我连个求助的人都没有。断断续续人越来越少。
   这让我想起了我大二那年上晚自习,刚出门口,看到下毛毛雨,没在意,直接往回走,前边两个小女

生,有一个就回过头来,要把我送回去,后来就送我回宿舍了,呵呵~~~~
   相信这种事一辈子也就那么一次吧,不过已经很满足了,后来经常怀念起那次~~~~~~
   最后雨下的小点了之后,一口气跑回去了,幸运的是,书没被淋到多少。
posted @ 2008-09-26 12:51 独履_天涯 阅读(13) | 评论 (0) | 编辑 收藏
 

2008年9月20日

从亨者提取企业黄页信息的任务
功能是在输入一个城市或地区名称后,能提取所有的该地区的企业信息
在刚刚总算完成了个大概,用了一天多点的时间,主要代码如下
void CCompanyInformationView::OnCollectInformation()
{
    CString strURL="http://www.hengzhe.com/Company/gs.html?q=";
    CWTString wts;
    CString str ;
    CString LinkSavePath="E:\\LinkSave.txt";   
    CStdioFile myFile;
    myFile.Open(LinkSavePath,CFile::modeCreate|CFile::modeReadWrite);
    myFile.Close();
    m_bar.GetDlgItemText(idcArea,str);
    strURL+=wts.URLEncode(wts.GB2312ToUTF8(str));
    strURL+="&ar=%e5%85%a8%e5%9b%bd";
    LoopPageLink(strURL);
   
}
//-----递归取页数
void CCompanyInformationView::LoopPageLink(CString strURL)
{
    CString strInitURL=strURL;
    CWTString wts;
    CString str ;
    GetPageLink(strURL);

    if(ant.Request("GET",strInitURL)<1){
        CString strError = ant.GetError();
        return ;
    }
    str=wts.UTF8ToGB2312(ant.m_strBody);
    WriteFileText("E:\\Company.htm",str);
   
    reader.SetHtml(str);
    LPCTSTR lpTag;
    CString strValue,strName,strInside;
   
    /*for(;;)
    {
       
        lpTag=reader.GetNextTag();
        strName=reader.GetTagName(lpTag);
        if(strName!="a")  continue;
        strInside=reader.GetInnerHtml(lpTag);
        strValue=reader.GetTagAttribute(lpTag,"href");
        if(strValue.Find("gs.html?")<0)  continue;
        str="http://www.hengzhe.com/Company/"+strValue;
        GetPageLink(str);
        break;
    }*/
    for(;;)
    {
        lpTag=reader.GetNextTag();
        strName=reader.GetTagName(lpTag);
        if(strName!="a")  continue;
        if(strName.Compare("/html")==0)  break;
        strInside=reader.GetInnerHtml(lpTag);
        if(strInside.Compare("下一页")!=0) continue;
        strValue=reader.GetTagAttribute(lpTag,"href");
        strValue="http://www.hengzhe.com/Company/"+strValue;
        LoopPageLink(strValue);
        break;
    }
     

}


//----------------------------------取一个页面链接的所有公司
void CCompanyInformationView::GetPageLink(CString strURL)
{
    CWTString wts;
    CString str ;
    WriteFileText("E:\\kankan.txt",strURL);
    if(ant.Request("GET",strURL)<1){
        CString strError = ant.GetError();
        return ;
    }
    str=wts.UTF8ToGB2312(ant.m_strBody);
    CString LinkSavePath="E:\\LinkSave.txt";   
    CStdioFile myFile;
    myFile.Open(LinkSavePath,CFile::modeReadWrite);
    reader.SetHtml(str);
    LPCTSTR lpTag;
    CString strValue,strName,strInside;
    for(;;)
    {
       
        lpTag=reader.GetNextTag();
        strName=reader.GetTagName(lpTag);
        if(strName.Compare("/html")==0) break;
        if(strName!="a")  continue;
        strValue=reader.GetTagAttribute(lpTag,"href");
        if(strValue.Find("vi.html?")<0) continue;
        str="http://www.hengzhe.com/Company/"+strValue;
        myFile.WriteString("\r\n");
        myFile.WriteString(str);
           
    }
    myFile.Close();

    SaveData();

}
//----------------------------------
void CCompanyInformationView::SaveData()//数据库操作将某个企业基本信息保存到数据库
{
       
    CWTString wts;
    CString str;
    CSQLInsert sql;
    CString strURL;
    CStdioFile myFile;
    myFile.Open("E:\\LinkSave.txt",CFile::modeRead);
    myFile.ReadString(strURL);
    for(;;)
    {
        myFile.ReadString(strURL);
        if (strURL.IsEmpty())  break;

        if(ant.Request("GET",strURL)<1){
            CString strError = ant.GetError();
            return ;
        }
        sql.SetTableName("CompanyInformation");   
        int index=dbGetLastKeyId(m_pDB,"CompanyInformation")+1;
        sql.SetFieldLong("KeyId",index);

        LPCTSTR lpTag;
        CString strValue,strName,strInside;
        int at1,at2;
        reader.SetHtml(wts.UTF8ToGB2312(ant.m_strBody));
        for(;;)
        {       
            lpTag=reader.GetNextTag();
            strName=reader.GetTagName(lpTag);
            if(strName.Compare("/body")==0)  break;
            if(strName.Compare("td")!=0)  continue;
            strValue=reader.GetTagAttribute(lpTag,"width");
            if(strValue.Compare("70%")==0)  continue;
            strInside=reader.GetInnerHtml(lpTag);
            if(strInside.Find("公司名称:")>=0)
            {
                strInside.TrimRight();

                at1=strInside.Find(":");
                str=strInside.Mid(at1+2,strInside.GetLength()-at1+3);
                str.TrimLeft();
                //str.TrimLeft(":");
                sql.SetFieldText("Customer",str);
            }
            else if(strInside.Find("所在区域:")>=0)
            {
                strInside.TrimRight();
                if(strInside.GetLength()<=5)  continue;
                at1=strInside.Find(":");
                at2=strInside.Find(".");
                str=strInside.Mid(at1+2,at2-at1-2);
                sql.SetFieldText("Province",str);
                str=strInside.Mid(at2+1,strInside.GetLength()-at2+1);
                str.TrimLeft();
                sql.SetFieldText("City",str);
            }
            else if(strInside.Find("联 系 人:")>=0)
            {
                strInside.TrimRight();
                if(strInside.GetLength()<=6)  continue;
                at1=strInside.Find(":");
                str=strInside.Mid(at1+2,strInside.GetLength()-at1);
                str.TrimLeft();
                sql.SetFieldText("Contact",str);
            }
            else if(strInside.Find("详细信息:")>=0)
            {           
                lpTag=reader.GetNextTag();
                lpTag=reader.GetNextTag();
                strInside=reader.GetInnerHtml(lpTag);
                strInside.TrimRight();
                str.TrimLeft();
                sql.SetFieldText("Abstract",strInside);
            }
            else if(strInside.Find("联系电话:")>=0)
            {
                strInside.TrimRight();
                if(strInside.GetLength()<=10)  continue;
                at1=strInside.Find("-");
                at2=strInside.Find("-",at1+1);
                str=strInside.Mid(at1+1,at2-at1-1);
                if(!str.IsEmpty())  sql.SetFieldText("Area",str);
                str=strInside.Mid(at2+1,strInside.GetLength()-at2);
                if(!str.IsEmpty())  sql.SetFieldText("Phone",str);
            }
            else if(strInside.Find("传 真:")>=0)
            {
                strInside.TrimRight();
                if(strInside.Find("-")>=0)
                {
                    at1=strInside.Find("-");
                    at2=strInside.Find("-",at1+1);
                    str=strInside.Mid(at2+1,strInside.GetLength()-at2);
                    str.TrimLeft();
                    sql.SetFieldText("Fax",str);
                }
            }
            else if(strInside.Find("移动电话:")>=0)
            {
                strInside.TrimRight();
                at1=strInside.Find(":");
                str=strInside.Mid(at1+2,strInside.GetLength()-at1);
                str.TrimLeft();
                at1=str.Find(">");
                str=str.Mid(at1+1,str.GetLength()-at1);
                if(str.IsEmpty()) continue;
                sql.SetFieldText("Mobile",str);
            }
            else if(strInside.Find("电子邮箱:")>=0)
            {       
                strInside.TrimRight();
                int ii=strInside.GetLength();
                if(strInside.GetLength()<=10)  continue;
                at1=strInside.Find(":");
                str=strInside.Mid(at1+1,strInside.GetLength()-at1);
                str.TrimLeft();
                sql.SetFieldText("Email",str);
            }
            else if(strInside.Find("公司地址:")>=0)
            {
                strInside.TrimRight();
                at1=strInside.Find(":");
                str=strInside.Mid(at1+2,strInside.GetLength()-at1);
                str.TrimLeft();
                sql.SetFieldText("Address",str);
            }
            else if(strInside.Find("公司网址:")>=0)
            {
                strInside.TrimRight();
                if(strInside.Find("www")<0&&strInside.Find("http")<0) continue;
                lpTag=reader.GetNextTag();
                strValue=reader.GetTagAttribute(lpTag,"href");
                sql.SetFieldText("Homepage",strValue);
            }       
        }
        CString strSQL=sql.GetSQL();
       
        if(m_pDB->Execute(strSQL)<1)
        {
            MessageBox(m_pDB->m_strError+"\r\n"+strSQL);
            return;
        }
        sql.DeleteContents();
        m_qdbgrid.Retrieve(m_pDB);
        m_grid.Invalidate();
    }
}

posted @ 2008-09-20 15:24 独履_天涯 阅读(17) | 评论 (0) | 编辑 收藏
 
仅列出标题