关于下载网页代码

chenyang80425 chenyang80425 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
我要采集这张页面(http://newtrade.jctrans.com/Demand/vxpxhp1673.html)的信息,但不能采集到联系电话,因为要登陆后才能看得到电话.代码如下,为何还是无法采集到联系电话呢?请问要如何实现
void CHtmlDlg::OnButton1()
{
CString strHttpName="http://newtrade.jctrans.com/Demand/vxpxhp1673.html"; // 需要提交数据的页面
CString strFormData = "txtName=chenyang80425&txtPassword=zjj58893035"; // 需要提交的数据,用户名和密码都正确

CInternetSession sess;
CHttpFile* fileGet;
CString strHeaders = _T("Content-Type: application/x-www-form-urlencoded"); // 请求头

try
{
fileGet=(CHttpFile*)sess.OpenURL(strHttpName);//打开文件
}
catch(CException* e)
{
fileGet = 0;
throw;
}

CString strSentence, strGetSentence = "";
if(fileGet)
{
DWORD dwStatus;
DWORD dwBuffLen = sizeof(dwStatus);
BOOL bSuccess = fileGet->QueryInfo(HTTP_QUERY_STATUS_CODE|HTTP_QUERY_FLAG_NUMBER, &dwStatus, &dwBuffLen);
if( bSuccess && dwStatus>= 200 &&dwStatus<300 )
{
BOOL result = fileGet->SendRequest(strHeaders, (LPVOID)(LPCTSTR)strFormData, strFormData.GetLength());
while(fileGet->ReadString(strSentence)) // 读取提交数据后的返回结果
{
strGetSentence = strGetSentence + strSentence + char(13) + char(10);
}
//AfxMessageBox(strGetSentence); // 显示返回网页内容
this->m_edit=strGetSentence;
UpdateData(FALSE);
}
else
{
strSentence.Format("POST出错,错误码:%d", dwStatus);
AfxMessageBox(strSentence);
}

fileGet->Close();
delete fileGet;
}
else
AfxMessageBox("不能找到网页文件!");

sess.Close();
}
...全文
评论 5
收藏 已收藏
分享
返回顶部
chenyang80425
VC/MFC 16,551 成员 421,605 内容