Search code examples
javaandroidseleniumnetwork-programmingselendroid

Getting URL from site after submitting form


So the site that Im targeting works like this:

The sites name is https://masterbattlerite.com/. https://masterbattlerite.com/ works like this:

  1. Enter username in search bar of the site
  2. Press the search button (or hit enter)
  3. The site directs you to the userpage with the username you entered.
  4. the URL is now something like https://masterbattlerite.com/238338348
  5. that number (238338348) is the id of the user
  6. I want to know how to get that id as a string in my app

I found out of Selendroid but you need some sort of server to be able to emulate a browser? My app will be released on the play store so I don't want my users needing to start their own selendroid server everytime to do this (maybe Im wrong)


Solution

  • In your code, can you use an HTTP library/framework and POST to the same location the site posts to and retrieve the id from the redirect the server sends? You may have to set some extra (possibly hidden on the webpage) parameters to get it to work.

    EDIT: ok, it's even easier with the site you mentioned... if you search for a username of bob, you just GET this URL: http://masterbattlerite.com/profile/bob/lookup and it returns some nice JSON with the id in it like so: {"status":"success","player":{"id":1268,"user_id":"5688","name":"bob","title":504,"avatar":30016}}

    BTW - I figured all of this out using the Chrome developer's tools. Learn to use it - it is your friend.