I need to follow the first result of a search on a website.
I open the website by feeding the Name that I am looking for from a .csv file so that it opens the website with the search already performed.
def name_to_url(name):
words = name.split(" ")
url = "http://website/search/results?Name="
end_of_url = "&Type=0&IncludeNlsp=True"
for word in words:
url += "%s+" % word
url += "%s" % end_of_url
return url
with open('file.csv', 'rb') as f:
reader = csv.reader(f)
for row in reader:
open_page(name_to_url(row[0]))
I know this may not be the prettiest or best way to do it but it is good enough for now. My main concern is how to follow the link that the search returns.
Let's say the name would be "Google" and the search returns a link with bold green text that reads "Google". I've had a look at mechanize but I can't figure out how to do it, mainly because the example on the website uses regular expressions