2013-08-25 3 views
0

나는 praticular 사이트를 쉽게 탐색 할 수 있도록 뭔가를하고 싶었지만 문제는 그 방법을 알지 못하거나 심지어 Excel에서도 가능하다는 것입니다.특정 텍스트에 대한 웹 페이지 검색

내가 원하는 것은 주어진 페이지에서 "과잉 공급"과 같은 텍스트를 검색하는 것입니다. 단어를 찾으면 주어진 셀에서 "전체"또는 "과잉 공급"또는 그 반대의 결과를 반환합니다.

이유는 Excel을 열고 각 페이지에 대해 별도의 결과를 제공하여 한 번에 100 개 이상의 페이지를 확인해야하기 때문입니다.

+1

참조 : http://stackoverflow.com/questions/9758107 –

답변

0

약간의 수정으로 원하는대로 할 수 있습니다.

내가 사용하는 웹 사이트에 로그인 할 때 코드가 있지만 필요한 것은 아닙니다.

큰 매크로에서 잘라내어 여기에 필요하지 않은 비트가있을 수 있습니다.

Sub scraper() 

     Dim site As String 
     Dim lastRow As Long 
     Dim ie 

     With ActiveSheet 
      lastRow = .Cells(.Rows.Count, "A").End(xlUp).Row 
     End With 

      Set ie = CreateObject("internetexplorer.application") 
      ie.Visible = True 

      ie.navigate site 

      'idle while ie is busy 
      Do 
      Loop Until ie.readystate = 3 
      Do 
      Loop Until ie.readystate = 4 

      With ie.document 
       .getelementbyid("UserName").Value = uName 
       .getelementbyid("Password").Value = uPass 
       .forms(0).submit 
      End With 
      On Error GoTo error 

      Do 
      Loop Until ie.readystate = 3 
      Do 
      Loop Until ie.readystate = 4 

      For i = 2 To lastRow 

       site = Range("A" & i).Value 
       ie.navigate site 

      Do 
      Loop Until ie.readystate = 3 
      Do 
      Loop Until ie.readystate = 4 


     msg = ie.document.Body.innerhtml 
     If InStr(msg, "Text To Find") = 0 Then 
      ActiveSheet.Range("B" & i).Value = "Not Found" 
     Else 
      ActiveSheet.Range("B" & i).Value = "Found" 
     End If 
jump: 
      Next i 
     Exit Sub 
error: 
    ActiveSheet.Range("B" & i).Value = "Unknown Error!" 
Resume jump 


End Sub 
+0

감사합니다. 매력처럼 일했습니다. – user99776644

관련 문제