VBA - 从网站搜索和读取数据

时间:2012-12-06 10:50:24

标签: excel excel-vba vba

我在Excel中有一个ID号列表(Patnets ID),根据他们的ID我想在this website上搜索。 然后,将ID超链接转移到详细表格,提取一些数据,如“标题”,“Anmelder / Inhaber”,......

是否有人知道VBA代码解决方案?

1 个答案:

答案 0 :(得分:1)

您想要使用XML Parsing对象。首先添加对Mircosoft XML的引用,v6.0。以下代码将帮助您入门,但您确实需要遵循HTML抓取教程来计算所有控件ID等

Sub DownloadFromWebsite()
    Dim objHTTP As New MSXML2.ServerXMLHTTP
    Dim urlLink As String, sResponseHTML As String, sPatentID as String, sPostData as String

    urlLink = "http://depatisnet.dpma.de/DepatisNet/depatisnet?action=einsteiger"

    ''Start up the parser and return the HTML
    objHTTP.Open "POST", urlLink, False
    objHTTP.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
    objHTTP.send ("")
   sResponseHTML = objHTTP.responseText

   'Now parse the sResponseHTML to identify the form objects such as textfield names and buttons
   'After parsing you can re "POST" using the .send method
   'The following is example post data *NOT* necessarily applicable to your case
   sPatentID = "23412334"
   sPostData = "theIDnameinHTML=" & sID & "submitbuttonID.x=40&submitbuttonID.y=10"
   objHTTP.send (sPostData)
   sResponseHTML = objHTTP.responseText

   'Now parse the response to see if you have your results
End Sub