0

I have a list of tennis players stored in a database. I want to use mechanize to scrape the atpworldtour.com site for information on those players. The search form is located on the home page and I can access it pretty easily with:

agent = Mechanize.new
url = "http://www.atpworldtour.com"
page = agent.get(url)
form = page.form()

However the input field has no name.Here's the markup for the search form:

<form id="siteSearch" class="site-search">
  <input type="search" placeholder="Search Players and Tournaments" class="search">
  <button id="closeSearch" type="button" class="close-search"></button>
  <div class="search-partner"><span> </span><img alt="" src=""></div>
</form>

I've tried to search ways to access a field with no name and came across these two questions but they both use the find_control method and I think that's python specific? It gives me an undefined method 'find_control' error at any rate.

I also had a look at this question and also took a look at the mechanize documentation for field_with and came up with:

pp form.field_with(:class => "search").value 

to try and print out the current value of the search field to see if that works but form.field_with(:class => "search") returns nil.

Am I going about this the wrong way? If anyone can point me towards the right path for at least getting the search submitted I'd much appreciate it.

Community
  • 1
  • 1
SoSimple
  • 701
  • 9
  • 30
  • That input doesn't have a name so it doesn't do anything in the form sense. I see that it's firing off ajax requests to http://www.atpworldtour.com/en/-/ajax/PredictiveContentSearch/GetPlayerResults/foo and http://www.atpworldtour.com/en/-/ajax/PredictiveContentSearch/GetTournamentResults/foo – pguardiario Nov 11 '15 at 00:22
  • Yeah I feel silly for not realising this sooner. Got a whole different problem on my hands now. Thanks for the feedback :) – SoSimple Nov 11 '15 at 10:37

0 Answers0