2016-12-07 4 views
0

GM 파트 웹 사이트에서 부품 번호 값의 범위에 대한 설명 목록을 만드는 것을 자동화하려고합니다.웹 사이트 텍스트의 일부를 Excel 셀로 가져 오는 방법

예를 들어

가, 다음은 부품 번호 23498355에 대한 링크입니다 - 나는 파트 설명 텍스트를 잡기 위해 노력하고있어 http://www.gmpartsdirect.com/oe-gm/23498355

"이 ABS 센서는 정품 OEM GM의 부품 번호 23498355이며 공장을 수행 우리는 모든 주문에 대해 빠른 배송으로 최고의 온라인 가격을 제공합니다. " 이 웹 페이지에서 Excel로 사용할 수 있습니다.

정보를 얻기 위해 다음 코드를 작성했지만이 특정 정보를 얻을 수있는 마지막 몇 줄을 완료하지 못했습니다.

Option Explicit 

Sub myConnection() 
    Dim oHtml, myData, Title, cste 
    Set oHtml = New HTMLDocument 
    With CreateObject("WINHTTP.WinHTTPRequest.5.1") 
     .Open "GET", "http://www.gmpartsdirect.com/oe-gm/23498355", False 
     .send 
     oHtml.body.innerHTML = .responseText 
    End With 
'Rest of the code to grab the exact part description 
End Sub 

이 작업이 완료되면 부품 번호 목록을 자동으로 처리하는 것이 좋습니다. 누군가이 코드를 완성하는데 도움을 줄 수 있습니까? 많은 "현대"문서 방법이 구현되지 않을 수 있습니다 이후 HTML을 구문 분석 MSHTML을 사용하여

답변

1

는 조금 제한되어 있지만, 당신은이 경우에 작동하도록 할 수 있습니다 거기 나 같은 noobs에 대한

Sub myConnection() 
    Dim oHtml, myData, Title, cste, d 
    Set oHtml = New MSHTML.HTMLDocument 


    With CreateObject("WINHTTP.WinHTTPRequest.5.1") 
     .Open "GET", "http://www.gmpartsdirect.com/oe-gm/23498355", False 
     .send 
     oHtml.body.innerHTML = .responseText 

     Set d = myGetElementsByClassName(oHtml, "div", "description_body") 
     If Not d Is Nothing Then 
      Debug.Print d.innerText 
     End If 

    End With 
'Rest of the code to grab the exact part description 
End Sub 


'return an element given its tag name and class name 
Function myGetElementsByClassName(doc, tagName, className) As Object 
    Dim el As Object 
    For Each el In doc.getElementsByTagName(tagName) 
     If el.className = className Then 
      Set myGetElementsByClassName = el 
      Exit Function 
     End If 
    Next el 
    Set myGetElementsByClassName = Nothing 
End Function 
+0

, VBA 창에서 _Tools -> References .. -> Microsoft HTML Object Library_를 클릭하여 Microsoft HTML 오브젝트 라이브러리를 활성화하십시오. – Vamsi

관련 문제