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.