• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Post method on form

YasserKhalil

Well-Known Member
Hello everyone
I have this link
http://www.res-ye.net
There are two forms with input text with the same data
<input type="text" name="num" id="i_text">

How can I determine any of them to deal with .. I need to put a number then clicking "Submit" button
 

Hi !

You can deal with a parent of the element, for example the Forms collection
and index 0 or 1 for the first two elements …
 
Here is the script. If you run it, you will get the table with data from that page.
Code:
Sub httpPost()

    Dim http As New XMLHTTP60, html As New HTMLDocument
    Dim htmla As Object, trow As Object, tcel As Object, ArgumentStr As String

    ArgumentStr = "grade=1&num=23&submit=Search"

    With http
        .Open "POST", "http://www.res-ye.net/class2.php", False
        .setRequestHeader "Content-type", "application/x-www-form-urlencoded"
        .send ArgumentStr
        html.body.innerHTML = .responseText
    End With

    Set htmla = html.getElementsByTagName("table")(2)
 
    For Each trow In htmla.Rows
        For Each tcel In trow.Cells
            c = c + 1: Cells(x + 1, c) = tcel.innerText
        Next tcel
        c = 0
        x = x + 1
    Next trow

End Sub


Btw, in this very line ArgumentStr = "grade=1&num=23&submit=Search", you can see there is a parameter num=23. If you change the number, you will get different tables. Hope you got me. Thanks.
 
That's wonderful and great Shahin. You are superstar at scraping
Can you guide me to resources to learn more about scraping?

As for the thread I need a specific point in fact ..
To scrape the name next to this string
الاســـــــم :
And the string next to
النتيجة النهائية
and the string next to المعدل
Each of these results would be put in columns B:D and in A will be the number (39) for example

Thank you very much for great help
 
You are superstar at scraping

As long as the above quotation is concerned, gurus like Marc L, Chihiro and Narayan are second to none. So, don't make them angry. I'm working on a project at this moment. However, as soon as I have time, I'll take a look. Thanks.
 
In fact all of the names you mentioned (Marc L, Chihiro and Narayan ) are superstars and no doubt and that doesn't lower their rank at all
I just named you because you started the help and take your time ..
I will be waiting for you my friend
 
One more thing: could you please clarify the string names in English as you did in Arabic. At the right most corner in the chrome address bar there is an icon in which if you hover your mouse you will see an option for translation popping up. Just press that.
 
Hey there!!! Give this a try. It will generate results based on your provided sitting number and gets placed in it's right position. I've used offset property so no loop is required here. Thanks.
Code:
Sub result_generator()

    Dim http As New XMLHTTP60, html As New HTMLDocument, ArgumentStr As String
    Dim posts As Object, post As Object, elems As Object, elem As Object
   
    [B1:E1].Value = [{"Sitting Number","Name","Final Result","Rate"}]
    ArgumentStr = "grade=1&num=24&submit=Search"
    With http
        .Open "POST", "http://www.res-ye.net/class2.php", False
        .setRequestHeader "Content-type", "application/x-www-form-urlencoded"
        .send ArgumentStr
        html.body.innerHTML = .responseText
    End With

    Set elems = html.getElementsByTagName("td")
    ActiveCell.Offset(1, 1) = elems(1).innerText
    Set posts = html.getElementById("success").getElementsByTagName("h3")
    ActiveCell.Offset(1, 2) = posts(0).innerText
    Set elem = html.getElementsByClassName("na")(0).getElementsByTagName("span")
    ActiveCell.Offset(1, 3) = elem(1).innerText
    Set post = html.getElementsByClassName("na")(0).getElementsByTagName("span")
    ActiveCell.Offset(1, 4) = post(2).innerText
    ActiveCell.Offset(1, 0).Select
       
End Sub

Btw, just tell me this is not what you wanted.
 
Last edited:
You're awesome and wonderful
Thank you very much for great help

Can you give me some powerful resources to learn the scraping from?
 
Thank you very very much Mr. Shahin
You have helped me a lot. As for dealing with the worksheet and cells I could change these tiny matters. You have done the essence and the most important part for me
Thanks a lot .. Best Regards
 
Back
Top