POST request problem after website update

fotodj

New Member
Joined
Jul 19, 2014
Messages
36
Office Version
  1. 2016
Platform
  1. Windows
It seems like website was updated and they did some minor changes but I can not figure out what I need to correct... if anybody could help?

Example:
Search on Military Database for serial 80-0223 was automatically input in Excel's fields ic. Serial. Code, Type, CN etc. ,
right now I am not getting any errors but no data is retrieved


VBA Code:
 Dim cel As Range, ms As Worksheet, dom As HTMLDocument, loopRange As Range
    Const SEARCH_URL As String = "https://www.scramble.nl/index.php?option=com_mildb&view=search"

' USAF --------------------------------------------------------------------------------------------------------------------------

    Set ms = ThisWorkbook.Worksheets("Scramble")
    Set dom = New HTMLDocument
    Set loopRange = ms.Range("B2:B" & ms.Range("B" & Rows.Count).End(xlUp).row).SpecialCells(2)

    Application.ScreenUpdating = False

    With CreateObject("winhttp.winhttprequest.5.1")

        For Each cel In loopRange

            .Open "POST", SEARCH_URL, False
            .setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
            .send "Itemid=60&af=usaf&serial=" & cel & "&sbm=Search&code=&searchtype=&unit=&cn="
            dom.body.innerHTML = .responseText
            Dim recordFields As Object

            Set recordFields = dom.querySelectorAll(".rowBord td")

            If recordFields.Length > 0 Then
                With cel
                    .Offset(, -1) = recordFields.Item(2).innerText 'Type
                    .Offset(, 2) = recordFields.Item(1).innerText 'Code
                    .Offset(, 3) = recordFields.Item(4).innerText 'Unit
                    .Offset(, 10) = recordFields.Item(3).innerText 'C/N
                    .Offset(, 11) = recordFields.Item(5).innerText 'Status
                    .Offset(, 7) = "USAF"
               End With
            End If
        Next
    End With
    Application.ScreenUpdating = True
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
The URL you're using will need to be updated - the code is contacting the site, but the servers are returning with a 404 error - meaning that the page doesn't exist (anymore). The text of the response packet says;
"Aircraft on runway, go-around...Something has gone wrong unfortunately and you've been redirected to a (landing)page that doesn't exist. Return to the homepage and try again.Subscribe to Scramble
As a member you get access to all our premium content and benefits learn more Follow us and keep in touch"
I would suggest trying to search for the item again manually, make a note of the resulting URL and then update the code.
 
Upvote 0
Can you find the web page if you did it manually? I did a search for that number on the site, and it came up with 13 hits, but it isn't immediately clear to me which one you're after.

We need to change something in this string: "Itemid=60&af=usaf&serial=" & cel & "&sbm=Search&code=&searchtype=&unit=&cn="

Though, I suspect that we can ignore everything after "sbm=Search"

Do you know what might be meant by the parameters Itemid (it equals 60) and af (which is usaf)?
 
Upvote 0
When I look at my code which was working before , when I wanted to look in Military Database for
American Air Forces option Air Force (1948 - Now) ( Military Database) that part of the code was
.send "Itemid=60&af=usaf&serial=" & cel & "&sbm=Search&code=&searchtype=&unit=&cn="

for USA - Navy & Marines (Military Database) code was that part of the code was
.send "Itemid=60&af=usn&serial=" & cel & "&sbm=Search&code=&searchtype=&unit=&cn="

for USA - Coast Guard
.send "Itemid=60&af=uscg&serial=" & cel & "&sbm=Search&code=&searchtype=&unit=&cn="


So it looks like 60&af was the parameter for American Air Forces part of database which later divides into usaf, usn, etc. options
I think the clue is in the view source page view:

<div class="control-label"><label id="jform_af_am-lbl" for="jform_af_am">
<strong>American Air Forces</strong></label>
</div>
<div class="controls"><select id="jform_af_am" name="jform[af_am]" onchange="this.form.submit();">
<option value="" selected="selected"></option>
<option value="ar">Argentina</option>
<option value="bs">Bahamas</option>
<option value="bb">Barbados</option>
<option value="bz">Belize</option>
<option value="bo">Bolivia</option>
<option value="br">Brazil</option>
<option value="ca">Canada</option>
<option value="cl">Chile</option>
<option value="co">Colombia</option>
<option value="cr">Costa Rica</option>
<option value="cu">Cuba</option>
<option value="do">Dominican Republic</option>
<option value="ec">Ecuador</option>
<option value="sv">El Salvador</option>
<option value="gt">Guatemala</option>
<option value="gy">Guyana</option>
<option value="ht">Haiti</option>
<option value="hn">Honduras</option>
<option value="jm">Jamaica</option>
<option value="mx">Mexico</option>
<option value="ni">Nicaragua</option>
<option value="pa">Panama</option>
<option value="py">Paraguay</option>
<option value="pe">Peru</option>
<option value="rss">Regional Security System</option>
<option value="sr">Surinam</option>
<option value="tt">Trinidad &amp; Tobago</option>
<option value="uy">Uruguay</option>
<option value="usaf">USA - Air Force (1948 - now)</option>
<option value="usar">USA - Army (1948 - now)</option>
<option value="usaaf">USA - Army Air Force (1907 - 1947)</option>
<option value="uscg">USA - Coast Guard</option>
<option value="nasa">USA - NASA</option>
<option value="usn">USA - Navy &amp; Marines</option>
<option value="ve">Venezuela</option>
</select>
</div>
 
Upvote 0
Upvote 0
The problem now is to change the old line .send "Itemid=60&af=usaf&serial=" & cel & "&sbm=Search&code=&searchtype=&unit=&cn=" to reach Military Database
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,323
Members
452,635
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top