syed_iqbal
03-15-2017, 01:10 PM
Hi,
I want to download all company names from the web. I wrote code but one line of code is not working. pls go through the code and correct it
Note: here my intention is, I want to scrape/download specific URL's from the web page. if URL contain "http://money.rediff.com/companies/", then I want to download that URL. for this I was used instr function. but this function is not working. Pls, help me.
Sub downloadallcompanynames()
Dim IE As New SHDocVw.InternetExplorer
Dim num As Integer
Dim lrow As Long
Dim str As String
Dim alllinks As mshtml.IHTMLElementCollection
ThisWorkbook.Sheets("Sheet1").Activate
ActiveSheet.Cells(2, 1).Select
Set IE = New SHDocVw.InternetExplorer
IE.Visible = True
IE.navigate "http://money.rediff.com/companies"
Do While IE.ReadyState <> READYSTATE_COMPLETE
Loop
Set htmldoc = IE.Document
Set HTMLAs = htmldoc.getElementsByTagName("a")
For Each HTMLA In HTMLAs
num = InStr(HTMLA.innerText, "http://money.rediff.com/companies") 'this line of code is not working
If num > 0 Then
Debug.Print HTMLA.getAttribute("href")
ActiveCell.Value = HTMLA.getAttribute("href")
ActiveCell.Offset(1, 0).Select
End If
Next HTMLA
End Sub
Pls add another code for download all URL's from multiple pages from above website. i did not added.
thank you in advance
I want to download all company names from the web. I wrote code but one line of code is not working. pls go through the code and correct it
Note: here my intention is, I want to scrape/download specific URL's from the web page. if URL contain "http://money.rediff.com/companies/", then I want to download that URL. for this I was used instr function. but this function is not working. Pls, help me.
Sub downloadallcompanynames()
Dim IE As New SHDocVw.InternetExplorer
Dim num As Integer
Dim lrow As Long
Dim str As String
Dim alllinks As mshtml.IHTMLElementCollection
ThisWorkbook.Sheets("Sheet1").Activate
ActiveSheet.Cells(2, 1).Select
Set IE = New SHDocVw.InternetExplorer
IE.Visible = True
IE.navigate "http://money.rediff.com/companies"
Do While IE.ReadyState <> READYSTATE_COMPLETE
Loop
Set htmldoc = IE.Document
Set HTMLAs = htmldoc.getElementsByTagName("a")
For Each HTMLA In HTMLAs
num = InStr(HTMLA.innerText, "http://money.rediff.com/companies") 'this line of code is not working
If num > 0 Then
Debug.Print HTMLA.getAttribute("href")
ActiveCell.Value = HTMLA.getAttribute("href")
ActiveCell.Offset(1, 0).Select
End If
Next HTMLA
End Sub
Pls add another code for download all URL's from multiple pages from above website. i did not added.
thank you in advance