0

I am learning to use python 2.7 and ghost.py to do some web scraping, I googled ghost.py a lot but I found very little documentation or help on use it, which gives my a bumpy ride when learning ghost.py.

I wrote a little script below to try send a query to starbucks hong kong store locator:

ghost.open('http://www.starbucks.com.hk/store-locator/search') #1
ghost.wait_for_selector('input[name=searchField]')             #2
ghost.fill("#searchForm", {'searchField': 'Tsuen Wan'})        #3
ghost.fire_on("#searchForm",                                   #4
              "button button_search",                          #5
              expect_loading=True)                             #6
ghost.wait_for_selector('#searchResults')                      #7
ghost.evaluate("document.getElementById('searchResults')")     #8

I know what the code is doing for #1-3, but starting from #4, I start to get confused, I am not sure what should be entered for the second parameters of fire_on. The script currently gives me an error message of Unable to load requested page.

I have no experience on javascript, will this cause me lots of trouble?

Can anyone enlighten me a bit on ghost.py? or should I turn to use something else?

lokheart
  • 23,743
  • 39
  • 98
  • 169

1 Answers1

0

It appears that ghost.fire_on takes the name of the form (e.g. <form name="formName">) with a submit argument followed by expect_loading.

I'm not sure why you have a # in your form name. Based on the docs it seems your code should look like: ghost.fire_on('formName', 'submit', expect_loading=True)

I don't think you have to specify a button as an argument for the submit method. Seems that the submit argument is sufficient to submit the form.

AutomaticStatic
  • 1,661
  • 3
  • 21
  • 42