Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,646
Default import search result from a website


Hi All,

I want to create a web query in which I can import result data of a search
in the website.

1. How can I provide search criteria and press a search button through VBA?
2. How can I import the search result? (I tried to select result table and
press import, but Excel told me that the web query didn't provide any data.)

I guess that it requires other techniques as well, any guidance appreciated
putting me in the right direction in this field.

Thanks,
Stefi

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default import search result from a website


the code below takes data from cell B2 and performs a google search. the
code put a plus sign between each key word like a real google search.
Actually this is a real google search.

Public Sub GoogleSearch()
'Use and input box for typing in the search words
Dim szSearchWords As String
Dim szResults As String
With Sheets("Sheet1")
szSearchWords = .Range("B2").Value
End With
If Not Len(szSearchWords) 0 Then Exit Sub

'Get keywords and validate by adding + for spaces between
szSearchWords = Replace$(szSearchWords, " ", "+")

Dim ie As Object 'InternetExplorer
Set ie = CreateObject("InternetExplorer.Application")
ie.Navigate "http://www.google.com/search?hl=en&q=" & _
szSearchWords & "&meta="

'Loop until the page is fully loaded
Const READYSTATE_COMPLETE = 4
Do Until ie.ReadyState = READYSTATE_COMPLETE
With ie
.Visible = True
End With
Loop

Set Results = ie.document.getelementsbytagname("P")
For Each itm In Results
If InStr(UCase(itm.innertext), "RESULTS") Then
MsgBox (itm.innertext)
Exit For
End If
Next itm

With Sheets("Sheet2")
RowCount = 1
For Each itm In ie.document.all
.Range("A" & RowCount) = itm.tagname
.Range("B" & RowCount) = itm.classname
.Range("C" & RowCount) = Left(itm.innertext, 1024)

RowCount = RowCount + 1
Next itm
.Cells.VerticalAlignment = xlTop
End With

Set Results = ie.document.getelementsbytagname("LI")
With Sheets("Sheet3")
RowCount = 1
For Each itm In Results
.Range("A" & RowCount) = itm.innertext
RowCount = RowCount + 1
Next itm
.Cells.VerticalAlignment = xlTop
End With
'Explicitly clear memory
Set ie = Nothing
End Sub






"Stefi" wrote:

Hi All,

I want to create a web query in which I can import result data of a search
in the website.

1. How can I provide search criteria and press a search button through VBA?
2. How can I import the search result? (I tried to select result table and
press import, but Excel told me that the web query didn't provide any data.)

I guess that it requires other techniques as well, any guidance appreciated
putting me in the right direction in this field.

Thanks,
Stefi

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,646
Default import search result from a website


Thanks Joel, I'm going to test and study it!
Stefi


€˛Joel€¯ ezt Ć*rta:

the code below takes data from cell B2 and performs a google search. the
code put a plus sign between each key word like a real google search.
Actually this is a real google search.

Public Sub GoogleSearch()
'Use and input box for typing in the search words
Dim szSearchWords As String
Dim szResults As String
With Sheets("Sheet1")
szSearchWords = .Range("B2").Value
End With
If Not Len(szSearchWords) 0 Then Exit Sub

'Get keywords and validate by adding + for spaces between
szSearchWords = Replace$(szSearchWords, " ", "+")

Dim ie As Object 'InternetExplorer
Set ie = CreateObject("InternetExplorer.Application")
ie.Navigate "http://www.google.com/search?hl=en&q=" & _
szSearchWords & "&meta="

'Loop until the page is fully loaded
Const READYSTATE_COMPLETE = 4
Do Until ie.ReadyState = READYSTATE_COMPLETE
With ie
.Visible = True
End With
Loop

Set Results = ie.document.getelementsbytagname("P")
For Each itm In Results
If InStr(UCase(itm.innertext), "RESULTS") Then
MsgBox (itm.innertext)
Exit For
End If
Next itm

With Sheets("Sheet2")
RowCount = 1
For Each itm In ie.document.all
.Range("A" & RowCount) = itm.tagname
.Range("B" & RowCount) = itm.classname
.Range("C" & RowCount) = Left(itm.innertext, 1024)

RowCount = RowCount + 1
Next itm
.Cells.VerticalAlignment = xlTop
End With

Set Results = ie.document.getelementsbytagname("LI")
With Sheets("Sheet3")
RowCount = 1
For Each itm In Results
.Range("A" & RowCount) = itm.innertext
RowCount = RowCount + 1
Next itm
.Cells.VerticalAlignment = xlTop
End With
'Explicitly clear memory
Set ie = Nothing
End Sub






"Stefi" wrote:

Hi All,

I want to create a web query in which I can import result data of a search
in the website.

1. How can I provide search criteria and press a search button through VBA?
2. How can I import the search result? (I tried to select result table and
press import, but Excel told me that the web query didn't provide any data.)

I guess that it requires other techniques as well, any guidance appreciated
putting me in the right direction in this field.

Thanks,
Stefi

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
import data from website Maximilian Harmstorf Excel Programming 5 November 8th 16 03:49 PM
Import External data from a Website MichaelRobert Excel Worksheet Functions 6 November 13th 08 02:25 PM
Import images from a website Thyag Excel Programming 1 October 31st 08 11:20 AM
Import data from a website to excel marsocgm Excel Worksheet Functions 1 July 10th 07 03:45 PM
How can I import a website into my excel sheet automatically ever. Mohamed El Hefnawy Excel Discussion (Misc queries) 2 April 13th 05 04:51 PM


All times are GMT +1. The time now is 05:25 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"