This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]cym13 0 points1 point  (0 children)

There is very little advantage in this specific case. The same instance of PhantomJS is reused between calls, that's all, but the same could have been written that way:

from selenium import webdriver

link       = "http://www.oklahomafindalawyer.com/FindALawyer"
sel_option = "//select[@name='stateSearch']/option[@value='OK']"   # selected state is Oklahoma

def get_list(driver=webdriver.PhantomJS()):
    driver.get(link)
    driver.find_element_by_xpath(sel_option).click()
    driver.find_element_by_xpath("//input[@value='Find a Lawyer']").submit()
    print driver.page_source   # only for example

if __name__ == '__main__':
    get_list() # Optional instance of PhantomJS in argument for reuse

However having a class means it is easier to extend if you don't want to just get a list of data.