I am trying to scrape questions, options and answers from this url (http://www.indiabix.com/general-knowledge/basic-general-knowledge/) but I have two issues:
1. In the ForEach loop, it has empty value and does not go in the following If Condition 2. Answer is not visible on webpage to scrape. It has a click event "View Answer" link (javascript I believe). Please help. Thanks Enum READYSTATE READYSTATE_UNINITIALIZED = 0 READYSTATE_LOADING = 1 READYSTATE_LOADED = 2 READYSTATE_INTERACTIVE = 3 READYSTATE_COMPLETE = 4 End Enum Sub ImportIndiaBixData() 'to refer to the running copy of Internet Explorer Dim ie As InternetExplorer 'to refer to the HTML document returned Dim html As HTMLDocument 'open Internet Explorer in memory, and go to website Set ie = New InternetExplorer ie.Visible = False ie.navigate "http://www.indiabix.com/general-knowledge/basic-general-knowledge/" 'Wait until IE is done loading page Do While ie.READYSTATE <> READYSTATE_COMPLETE Application.StatusBar = "Trying to go to StackOverflow ..." DoEvents Loop 'show text of HTML document returned Set html = ie.document 'close down IE and reset status bar Set ie = Nothing Application.StatusBar = "" 'clear old data out and put titles in Cells.Clear Dim QuestionList As IHTMLElement Dim Questions As IHTMLElementCollection Dim Question As IHTMLElement Dim RowNumber As Long Dim QuestionId As String Dim QuestionFields As IHTMLElementCollection Dim QuestionField As IHTMLElement Dim votes As String Dim views As String Dim QuestionFieldLinks As IHTMLElementCollection Set QuestionList = html.getElementById("ib-main-bar") Set Questions = QuestionList.Children RowNumber = 1 For Each Question In Questions 'if this is the tag containing the question details, process it If Question.className = "bix-td-qtxt" Then 'first get and store the question in first column QuestionId = Question.ID Cells(RowNumber, 1).Value = CLng(QuestionId) 'get a list of all of the parts of this question, 'and loop over them Set QuestionFields = Question.all For Each QuestionField In QuestionFields 'if this is the question's options, store it 'look for option A and store it under the question 'look for option B and store it under A 'look for option C and store it under B 'look for option D and store it under C 'click the 'View Answer' link programatically and store the correct answer Next QuestionField 'go on to next row of worksheet RowNumber = RowNumber + 6 End If Next Set html = Nothing End Sub -- Are you =EXP(E:RT) or =NOT(EXP(E:RT)) in Excel? And do you wanna be? It’s =TIME(2,DO:IT,N:OW) ! Join official Facebook page of this forum @ https://www.facebook.com/discussexcel FORUM RULES 1) Use concise, accurate thread titles. Poor thread titles, like Please Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get quick attention or may not be answered. 2) Don't post a question in the thread of another member. 3) Don't post questions regarding breaking or bypassing any security measure. 4) Acknowledge the responses you receive, good or bad. 5) Jobs posting is not allowed. 6) Sharing copyrighted material and their links is not allowed. NOTE : Don't ever post confidential data in a workbook. Forum owners and members are not responsible for any loss. --- You received this message because you are subscribed to the Google Groups "MS EXCEL AND VBA MACROS" group. To unsubscribe from this group and stop receiving emails from it, send an email to excel-macros+unsubscr...@googlegroups.com. To post to this group, send email to excel-macros@googlegroups.com. Visit this group at http://groups.google.com/group/excel-macros. For more options, visit https://groups.google.com/d/optout.