PureBasic 获取HTML内容的方法!WebGadget : get HTML text

代码来自:

http://forums.purebasic.com/english/viewtopic.php?t=17330

Code:

;
; Get HTML Text In WebGadget
;
; NOT COMPATIBLE WITH FREAK'S WebGadgetExtras.pb
;
Interface IHTMLDocument2_FIXED
QueryInterface(a,b)
  AddRef()
  Release()
  GetTypeInfoCount(a)
  GetTypeInfo(a,b,c)
  GetIDsOfNames(a,b,c,d,e)
  Invoke(a,b,c,d,e,f,g,h)
  get_Script(a)
  get_all(a)
  get_body(a)
  get_activeElement(a)
  get_images(a)
  get_applets(a)
  get_links(a)
  get_forms(a)
  get_anchors(a)
  put_title(a)
  get_title(a)
  get_scripts(a)
  put_designMode(a)
  get_designMode(a)
  get_selection(a)
  get_readyState(a)
  get_frames(a)
  get_embeds(a)
  get_plugins(a)
  put_alinkColor(a)
  get_alinkColor(a)
  put_bgColor(a)
  get_bgColor(a)
  put_fgColor(a)
  get_fgColor(a)
  put_linkColor(a)
  get_linkColor(a)
  put_vlinkColor(a)
  get_vlinkColor(a)
  get_referrer(a)
  get_location(a)
  get_lastModified(a)
  put_URL(a)
  get_URL(a)
  put_domain(a)
  get_domain(a)
  put_cookie(a)
  get_cookie(a)
  put_expando(a)
  get_expando(a)
  put_charset(a)
  get_charset(a)
  put_defaultCharset(a)
  get_defaultCharset(a)
  get_mimeType(a)
  get_fileSize(a)
  get_fileCreatedDate(a)
  get_fileModifiedDate(a)
  get_fileUpdatedDate(a)
  get_security(a)
  get_protocol(a)
  get_nameProp(a)
  write(a)
  writeln(a)
  open(a,b1,b2,b3,b4,c1,c2,c3,c4,d1,d2,d3,d4,e)
  close()
  clear()
  queryCommandSupported(a,b)
  queryCommandEnabled(a,b)
  queryCommandState(a,b)
  queryCommandIndeterm(a,b)
  queryCommandText(a,b)
  queryCommandValue(a,b)
  execCommand(a,b,c,d)
  execCommandShowHelp(a,b)
  createElement(a,b)
  put_onhelp(a1,a2,a3,a4)
  get_onhelp(a)
  put_onclick(a1,a2,a3,a4)
  get_onclick(a)
  put_ondblclick(a1,a2,a3,a4)
  get_ondblclick(a)
  put_onkeyup(a1,a2,a3,a4)
  get_onkeyup(a)
  put_onkeydown(a1,a2,a3,a4)
  get_onkeydown(a)
  put_onkeypress(a1,a2,a3,a4)
  get_onkeypress(a)
  put_onmouseup(a1,a2,a3,a4)
  get_onmouseup(a)
  put_onmousedown(a1,a2,a3,a4)
  get_onmousedown(a)
  put_onmousemove(a1,a2,a3,a4)
  get_onmousemove(a)
  put_onmouseout(a1,a2,a3,a4)
  get_onmouseout(a)
  put_onmouseover(a1,a2,a3,a4)
  get_onmouseover(a)
  put_onreadystatechange(a1,a2,a3,a4)
  get_onreadystatechange(a)
  put_onafterupdate(a1,a2,a3,a4)
  get_onafterupdate(a)
  put_onrowexit(a1,a2,a3,a4)
  get_onrowexit(a)
  put_onrowenter(a1,a2,a3,a4)
  get_onrowenter(a)
  put_ondragstart(a1,a2,a3,a4)
  get_ondragstart(a)
  put_onselectstart(a1,a2,a3,a4)
  get_onselectstart(a)
  elementFromPoint(a,b,c)
  get_parentWindow(a)
  get_styleSheets(a)
  put_onbeforeupdate(a1,a2,a3,a4)
  get_onbeforeupdate(a)
  put_onerrorupdate(a1,a2,a3,a4)
  get_onerrorupdate(a)
  toString(a)
  createStyleSheet(a,b,c)
EndInterface

Interface IHTMLElement_FIXED
  QueryInterface(a,b)
  AddRef()
  Release()
  GetTypeInfoCount(a)
  GetTypeInfo(a,b,c)
  GetIDsOfNames(a,b,c,d,e)
  Invoke(a,b,c,d,e,f,g,h)
  setAttribute(a,b,c)
  getAttribute(a,b,c)
  removeAttribute(a,b,c)
  put_className(a)
  get_className(a)
  put_id(a)
  get_id(a)
  get_tagName(a)
  get_parentElement(a)
  get_style(a)
  put_onhelp(a1,a2,a3,a4)
  get_onhelp(a)
  put_onclick(a1,a2,a3,a4)
  get_onclick(a)
  put_ondblclick(a1,a2,a3,a4)
  get_ondblclick(a)
  put_onkeydown(a1,a2,a3,a4)
  get_onkeydown(a)
  put_onkeyup(a1,a2,a3,a4)
  get_onkeyup(a)
  put_onkeypress(a1,a2,a3,a4)
  get_onkeypress(a)
  put_onmouseout(a1,a2,a3,a4)
  get_onmouseout(a)
  put_onmouseover(a1,a2,a3,a4)
  get_onmouseover(a)
  put_onmousemove(a1,a2,a3,a4)
  get_onmousemove(a)
  put_onmousedown(a1,a2,a3,a4)
  get_onmousedown(a)
  put_onmouseup(a1,a2,a3,a4)
  get_onmouseup(a)
  get_document(a)
  put_title(a)
  get_title(a)
  put_language(a)
  get_language(a)
  put_onselectstart(a1,a2,a3,a4)
  get_onselectstart(a)
  scrollIntoView(a)
  contains(a,b)
  get_sourceIndex(a)
  get_recordNumber(a)
  put_lang(a)
  get_lang(a)
  get_offsetLeft(a)
  get_offsetTop(a)
  get_offsetWidth(a)
  get_offsetHeight(a)
  get_offsetParent(a)
  put_innerHTML(a)
  get_innerHTML(a)
  put_innerText(a)
  get_innerText(a)
  put_outerHTML(a)
  get_outerHTML(a)
  put_outerText(a)
  get_outerText(a)
  insertAdjacentHTML(a,b)
  insertAdjacentText(a,b)
  get_parentTextEdit(a)
  get_isTextEdit(a)
  click()
  get_filters(a)
  put_ondragstart(a1,a2,a3,a4)
  get_ondragstart(a)
  toString(a)
  put_onbeforeupdate(a1,a2,a3,a4)
  get_onbeforeupdate(a)
  put_onafterupdate(a1,a2,a3,a4)
  get_onafterupdate(a)
  put_onerrorupdate(a1,a2,a3,a4)
  get_onerrorupdate(a)
  put_onrowexit(a1,a2,a3,a4)
  get_onrowexit(a)
  put_onrowenter(a1,a2,a3,a4)
  get_onrowenter(a)
  put_ondatasetchanged(a1,a2,a3,a4)
  get_ondatasetchanged(a)
  put_ondataavailable(a1,a2,a3,a4)
  get_ondataavailable(a)
  put_ondatasetcomplete(a1,a2,a3,a4)
  get_ondatasetcomplete(a)
  put_onfilterchange(a1,a2,a3,a4)
  get_onfilterchange(a)
  get_children(a)
  get_all(a)
EndInterface
;
Procedure.l GetBSTRLength(bstr)
  Length = WideCharToMultiByte_(#CP_ACP, 0, bstr, -1, 0, 0, 0, 0)
  ProcedureReturn Length
EndProcedure
;
Procedure.l ReadBSTRMem(*Buffer, bstr, Length)
  Length = WideCharToMultiByte_(#CP_ACP, 0, bstr, -1, *Buffer, Length, 0, 0)   
  ProcedureReturn Length
EndProcedure
;
Procedure WebGadget_GextHTMLText(WebGadget.l)
  Protected WebObject.IWebBrowser2, HTMLDoc.IHTMLDocument2_FIXED, DocDispatch.IDispatch, HTMLElement.IHTMLElement_FIXED
  WebObject = GetWindowLong_(GadgetID(WebGadget), #GWL_USERDATA)
 
  If WebObject/get_document(@DocDispatch) = #S_OK
    If DocDispatch/QueryInterface(?IID_IHTMLDocument2, @HTMLDoc) = #S_OK
      If HTMLDoc/get_body(@HTMLElement) = #S_OK
        If HTMLElement/get_innerHTML(@bstr_code) = #S_OK
         
          bstr_len = GetBSTRLength(bstr_code)
          If bstr_len
            *Buffer = AllocateMemory(bstr_len)
            If *Buffer
              If ReadBSTRMem(*Buffer, bstr_code, bstr_len) ; Get HTML code in *Buffer
                Debug PeekS(*Buffer) ; [warning string size limitation, better use memory functions !]
              EndIf
              FreeMemory(*Buffer)
            EndIf
          EndIf
         
          SysFreeString_(bstr_code)
        EndIf
      EndIf
      DocDispatch/Release()
    EndIf
  EndIf
  ProcedureReturn
 
EndProcedure

DataSection
IID_IHTMLDocument2: ; {332C4425-26CB-11D0-B483-00C04FD90119}
Data.l $332C4425
Data.w $26CB, $11D0
Data.b $B4, $83, $00, $C0, $4F, $D9, $01, $19       
EndDataSection

订正内容!

Blade wrote:
Error: Label not found (iid_ihtmldocument2)
Some userlibrary is needed?

No, the data section was missing (sorry).
Fixed.
Code:
DataSection
IID_IHTMLDocument2: ; {332C4425-26CB-11D0-B483-00C04FD90119}
Data.l $332C4425
Data.w $26CB, $11D0
Data.b $B4, $83, $00, $C0, $4F, $D9, $01, $19       
EndDataSection

For tools, jaPBe/PBIDE plugins and libs, visit http://people.freenet.de/gnozal

作者邮箱: mailto:gnozal@freenet.de

作者主页 http://people.freenet.de/gnozal/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值