2

I want to automate this URL. My inputs as an example:

Input boxes:

افزودن صندوق with id="symbolSearch"

افزودن شاخص with id="indexSearch"

some values for symbolSearch:

I search کیان then I click on آوای ثروت کیان-در سهام

I search خوارزمی then I click on مشترك خوارزمي-در سهام

some values for indexSearch:

I search شاخص کل then I click on شاخص کل

I search شاخص کل then I click on شاخص كل (هم وزن)

How can I automate this in VBA ?

NOTE: Each element in "symbolSearch" associate with a mutual fund which has specific RegNo. The URL search elements within this link

Sub MakeChart()

    Dim appIE As Object
    Set appIE = CreateObject("internetexplorer.application")

    'Get the WebPage Content to HTMLFile Object
    With appIE
        .navigate "http://www.fipiran.ir/AnalysisTools/MFInteractiveChart"
        .Visible = True

        'wait until the page loads
        Do While .Busy Or .readyState <> READYSTATE_COMPLETE
            DoEvents
        Loop
        Application.Wait (Now + TimeValue("00:00:05"))

        For Each cell In Range("C:C")
           If Not IsNumeric(cell) Or cell.Value = "" Or cell.EntireRow.Hidden Then GoTo Next_iteration
           '''
            **' codes to add RegNo in range C:C to webpage **


Next_iteration:
        Next

        .Quit
    End With
    Set appIE = Nothing
End Sub
5
  • Yes , I tried. this is part of my program in Excel VBA. The examples you sent is very basic but my question I think is not simple. Plaese don't misjudge me. Commented Nov 30, 2018 at 12:49
  • It may depend on your level of experience. Your request on the face of it (depending on access method and any javascript events on the page) looks like common requrests and certainly covered by examples on StackOverflow. You want to enter text in inputboxes and click buttons/ make dropdown selections. There are loads of examples of doing this with Internet Explorer and selenium basic with other browsers. If it turns out something really is difficult it would be good to see where you got stuck in the process Commented Nov 30, 2018 at 13:03
  • @AliM67 no judgment, but please share the code that you have tried to work with so far. :-) Commented Nov 30, 2018 at 13:04
  • I prefer simulate JavaScript function instead search-click. I don't know it is possible or not, I want to add many mutual funds with RegNo programmatically not with typing the names and click on them. I hope I could express my idea correctly. Commented Nov 30, 2018 at 13:09
  • @QHarr I added the code. I use developer tool of Chrome. The function that related to search box is "symbolSearch". Commented Nov 30, 2018 at 13:31

1 Answer 1

3

I am not sure I have understood fully. I can parse the regNos from the first link using a JSON parser and store those in an array. I can then concantenate those numbers into an XMLHTTP request URL string that returns JSON data which I store in another array which you could parse.

Option Explicit   
Public Sub GetInfo()
    Dim url As String, json As Object, item As Object, regNos(), responseInfo(), i As Long
    url = "http://www.fipiran.ir/AnalysisTools/MFAutocomplete?term="

    With CreateObject("MSXML2.XMLHTTP")
        .Open "GET", url, False
        .send
        Set json = JsonConverter.ParseJson(.responseText)

        ReDim regNos(1 To json.Count)
        ReDim responseInfo(1 To json.Count)
        For Each item In json
            i = i + 1
            regNos(i) = item("RegNo")
        Next
        For i = LBound(regNos) To 2  'UBound(regNos)
            .Open "GET", "http://www.fipiran.ir/AnalysisTools/MFHistory?regNo=" & CStr(regNos(i)), False
            .send
            responseInfo(i) = .responseText
            'Application.Wait Now + TimeSerial(0, 0, 1) '< == to avoid being blocked
        Next
    End With
End Sub

Example info in responseInfo array:

enter image description here

After adding the jsonconverter.bas to the project I add a reference via VBE> Tools > References to Microsoft Scripting Runtime.

Sign up to request clarification or add additional context in comments.

11 Comments

Thanks. I think I couldn't express my idea completely. You gather all RegNos and get the histories into an array. It is not my purpose. Let me explain more. I have for example 5 RegNos in excel and I want to see their charts in the webpage to compare. Manual way is that entering associate Names in search box and selecting them. But we have the RegNos of these 5 fund (and the Names as well), so I wonder it can be possible to add them programmatically and watch and compare their chart?
In manual way the name is enough. The 5 fund is an example. The regno are read from excel (Column C) and the names there are in column B. The box you ask is "symbolSearch" as I mentioned in first post.
Please let me take some screenshots
The problem I have is I can enter only non Persian characters with my settings so the drop down never appears for me to be able to make the selection. Do you use selenium basic at all?
For example: I can enter an English term in the search box but as IE is launched in persian I cannot pull up the drop down. pastebin.com/ni1gU6rk
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.