1

I'm using MS Access 2010 to make web scrape at Google page.

My scenario

  • Table1 with column A with some words to search and column B to store the number of results, C the day I made the query and D the time.
  • An execute search Macro
  • Column A can be changed so I need to do the search only when I press the check button

My doubts:

  1. I've been reading about XMLHttpRequest but finally, I don't get if for a "small" search is better to use "GET" or "POST" method
  2. I can change the Google home page but I can't change search term and make the query by click the button. I only receive as responseText the original HTML text from URL base (www.google.com)

The code I have so far:

  Option Compare Database
  Sub test()

  Dim XMLPage As New MSXML2.XMLHTTP60
  Dim rs As DAO.Recordset
  Dim search As Object

  ' Create the recordset with all the values we have at Column A At Table1
  Set rs = CurrentDb.OpenRecordset("SELECT * From Table1")

  'Establish the URL from I want to scrape 
    myUrl = "www.google.es"

  Do Until rs.EOF
    XMLPage.Open "GET", myUrl, False
    XMLPage.setRequestHeader "Content-Type", "application/x-222-form-urlencoded"
    ' With XMLPage
     Set search = rs("WordSearch")
     XMLPage.Document.getElementsByClassName("iblpc") = rs!WordSearch
   'End With
    request.send
 HTMLDoc = XMLPage.responseText
   Debug.Print HTMLDoc
  Loop
Set XMLPage = Nothing
End Sub

I don't achieve to put the words I have at Wordsearch column and click on the search button and store the values indicated into the other columns. Any help will be very helpful

Gord Thompson
  • 116,920
  • 32
  • 215
  • 418
Judith
  • 33
  • 7
  • I have figured out how to loop recordset and conduct search with each record value but not how to grab the number of results from page. The number of results is in an element with ID "result-stats". It would be a string like "About 3,000,000 results (0.68 seconds)". You want to save the number 3,000,000? – June7 Jul 15 '20 at 01:36
  • Hi ! I only must record the number of occurrences, not the occurrences itself. So i.e. if I have the word country at ColumnA I must search it at google and note 2.0000.000 (only the number) at column B and 16/07/2020 at columns. And go to the next row and search for hope and note the number of occurentes and the day ,,, and so on. I hope you can figure out how to do ... thanks for all your help ! – Judith Jul 15 '20 at 01:45
  • 1
    I get error message that page object does not have Document property. I give up. – June7 Jul 15 '20 at 20:57
  • I’ve achieved half of solution. If I can find it I hope I try to put it here to help some one can be interested in. Thank you for helping and trying. I try to give you votes or points for the effort but I don’t know if I make it well – Judith Jul 15 '20 at 21:11

0 Answers0