读书人

操作网页。该怎么解决

发布时间: 2012-03-20 14:01:11 作者: rapoo

操作网页。
void __fastcall TForm1::Button1Click(TObject *Sender)
{ Variant vBrowser;

try
{
// 创建一个IE对象
vBrowser = Variant::CreateObject("InternetExplorer.Application");//可以不固定IE吗?
}
catch(...)
{
ShowMessage("IE Loading fail");
vBrowser = Unassigned;

return;
}

String strUrl = "http://www.blu-ray.com";

vBrowser.OleProcedure("Navigate", strUrl.c_str());
vBrowser.OlePropertySet("Width", 800);
vBrowser.OlePropertySet("Height", 600);
vBrowser.OlePropertySet("Visible", true);
Variant vDoc = vBrowser.OlePropertyGet("document");
Variant vAllTag = vDoc.OlePropertyGet("All");

vAllTag.OlePropertyGet("iptUser").OlePropertySet("InnerText", "英文名");


// 执行页面中提交按钮的提交方法
vAllTag.OlePropertyGet("btlogin").OleFunction("Click");

// 等待浏览器打开页面完毕
while(vBrowser.OlePropertyGet("Busy"))
{}


}
一个搜索图片的网站,http://www.blu-ray.com";
输入 英文名 ,点击搜索按钮。
上面的例子是妖哥,本来想先试试,
结果IE都没打开。浏览器 ,可以不固定IE吗?

[解决办法]
OLE专业户来也!!!

C/C++ code
Variant vBrowser;try{    // 创建一个IE对象    vBrowser = Variant::CreateObject("InternetExplorer.Application");}catch(...){    ShowMessage("IE Loading fail");    vBrowser = Unassigned;    return;}String strUrl = "http://www.blu-ray.com";vBrowser.OleProcedure("Navigate", strUrl.c_str());vBrowser.OlePropertySet("Width", 800);vBrowser.OlePropertySet("Height", 600);vBrowser.OlePropertySet("Visible", true);// 等待浏览器打开页面完毕while(vBrowser.OlePropertyGet("Busy"))    Application->ProcessMessages();Variant vDoc = vBrowser.OlePropertyGet("document");Variant vAllTag = vDoc.OlePropertyGet("All");// 填充页面中的用户名框, 注意这个 vb_login_username 是根据页面中的值提取出来vAllTag.OlePropertyGet("vb_login_username").OlePropertySet("InnerText", "用户名");// 填充页面中的密码框, vb_login_password 的字符串也是从页面中提取出来的vAllTag.OlePropertyGet("vb_login_password").OlePropertySet("InnerText", "密码");// 执行页面中Form的提交方法vAllTag.OlePropertyGet("loginform").OleFunction("Submit"); 

读书人网 >C++ Builder

热点推荐