0

我正在学习使用 python 2.7 和 ghost.py 进行一些网络抓取,我搜索ghost.py了很多,但我发现很少有文档或使用帮助,这让我在学习 ghost.py 时遇到了困难。

我在下面写了一个小脚本来尝试向星巴克香港商店定位器发送查询:

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

我知道代码在做什么#1-3,但是从 开始#4,我开始感到困惑,我不确定应该为 的第二个参数输入什么fire_on。该脚本当前给了我一条错误消息Unable to load requested page

我对javascript没有经验,这会给我带来很多麻烦吗?

任何人都可以在ghost.py上给我一些启发吗?还是我应该转而使用其他东西?

4

1 回答 1

0

看起来它ghost.fire_on采用表单的名称(例如<form name="formName">),submit后面跟着一个参数expect_loading

我不确定为什么您的表单名称中有 # 。根据文档,您的代码似乎应该如下所示: ghost.fire_on('formName', 'submit', expect_loading=True)

我认为您不必将按钮指定为提交方法的参数。看来submit论据足以提交表格。

于 2014-11-10T18:03:37.613 回答