带frame的php网站,利用webbrower想实现自动登录并自动分析获取网页中的数据,该网页中的数据定时自动刷新。
见有利用IHTMLDocument2的方法,用Olevariant进行赋值;因为不知道网页上对应input、submit控件的名称,所以不知道可行否;我使用o:=wb.OleObject.document.all.tags('input',0);后,o.value:=xx的时侯抛异常,提示automation object不支持value方法。
急~
见有利用IHTMLDocument2的方法,用Olevariant进行赋值;因为不知道网页上对应input、submit控件的名称,所以不知道可行否;我使用o:=wb.OleObject.document.all.tags('input',0);后,o.value:=xx的时侯抛异常,提示automation object不支持value方法。
急~
view source
o:=wb.OleObject.document.all.tags('input',0);后,o.value:=xx的时侯抛异常,提示automation object不支持value方法。
document.all.tags returns a collection. you should locate the input by its type, location or style.
如何获取带frame网页中的数据呢?是一个表单,可能有多页,php的网站
对于frame中相关页面的tagname我用以下方法进行遍历,发现取得的tagname值均为html,为什么?
doc:=Wb.document as IHtmlDocument2;
frameCol:=doc.frames;
for i:=0 to frameCol.Length-1 do
begin
vi:=i;
frame:=frameCol.Item(vi);
frame.QueryInterface(IID_IHTMLWindow2,framewin2);
if LowerCase(framewin2.name)='frame1' then
begin
mmo.Lines.Add(framewin2.document.body.innerHTML);
doc2:=framewin2.document as IHtmlDocument2;
for j:=0 to doc2.all.length-1 do
begin
_element:= doc2.all.item(i,EmptyParam) as IHTMLElement;//估计是这句话的问题,但不知道如何改
mmo.Lines.Add(_element.tagname);
end;
end;
我就是这样做的, 分析很畅快,而且不会出错
我需要获取指定frame的table中的数据,最好是一次获取多页的数据
还有就是关于自动登录后,如何等待提交成功后页面的完成?
2 handle the DocumentComplete event
public static void SaveTableByColumn(IHTMLTable table, StringDictionary container)
{
if (table == null)
return;
if (container == null)
return;
foreach (object o in table.rows)
{
IHTMLTableRow row = (IHTMLTableRow)o;
for (int j = 0; j < row.cells.length / 2; j++)
{
string key = ((IHTMLElement)row.cells.item(j, 0)).innerText;
string value = ((IHTMLElement)row.cells.item(j + 1, 0)).innerText;
if (key != null && value != null)
{
key = key.Trim();
value = value.Trim();
if (key.Length > 0)
container.Add(key, value);
}
}
}
}
[CLSCompliant(false), ComVisible(false)]
public static List<IHTMLTable> GetDescentsTables(IHTMLElement htmlElement)
{
List<IHTMLTable> tableList=new List<IHTMLTable>();
if (htmlElement==null)
return tableList;
IHTMLElementCollection formDescents = (IHTMLElementCollection)htmlElement.all;
foreach (object o in formDescents)
{
IHTMLElement he = (IHTMLElement)o;
if (he.tagName.ToLower().CompareTo("table")==0)
{
IHTMLTable t = (IHTMLTable)he;
tableList.Add(t);
}
}
return tableList;
}
[CLSCompliant(false), ComVisible(false)]
public static List<IHTMLTable> GetChildTables(IHTMLElement htmlElement)
{
List<IHTMLTable> tableList = new List<IHTMLTable>();
if (htmlElement == null)
return tableList;
IHTMLElementCollection formChildren= (IHTMLElementCollection)htmlElement.children;
foreach (object o in formChildren)
{
IHTMLElement he = (IHTMLElement)o;
if (he.tagName.ToLower().CompareTo("table") == 0)
{
IHTMLTable t = (IHTMLTable)he;
tableList.Add(t);
}
}
return tableList;
}
doc:=WebBrowser.document as IHtmlDocument2;
frameCol:=doc.frames;
for i:=0 to frameCol.Length-1 do
begin
vi:=i;
frame:=frameCol.Item(vi);
frame.QueryInterface(IID_IHTMLWindow2,framewin2);
if LowerCase(framewin2.name)='frametable' then
begin
doc2:=framewin2.document as IHtmlDocument2;
_element:=doc2.get_all;
for j:=0 to doc2.all.length-1 do
begin
tbDisp:=_element.item(j,0);
if SUCCEEDED(tbDisp.QueryInterface(IHTMLTable,HtmlTblEle)) then
with HtmlTblEle do
begin
for m:=0 to HtmlTblEle.cols-1 do
begin
_element :=HtmlTblEle.rows;
for n:=0 to _element.length-1 do
begin
//如何将table内容输出?
// mmo.Lines.Add(_element.item(0,0));
end;
end;
end;
you have to detect the change of page numbers
不知道还有没有什么别的好方法?
为了能和页面进行交互,目前我只能想到加载页面并用shtml的方法对页面进行控制
还请tttk大虾多多指点