2

我正在尝试使用 spynner 自动单击 HTML 源代码中的某个按钮作为一个小测试。但我收到了这个错误。回溯(最后一次调用):文件“build\bdist.win32\egg\spynner\browser.py”,第 287 行,在 _on_reply AttributeError:'Browser' 对象没有属性'manager'

下面是我的代码,它遵循此处的指南:https ://github.com/makinacorpus/spynner/blob/master/examples/webkit_methods.py

import spynner
import libxml2

proxy_ip = "xxx.xxx.xxx.xxx";
browser = spynner.Browser()  

    # setting proxy ip  
browser.set_proxy(proxy_ip :'8080'); 
browser.show() 

try:  
        browser.load(url='http://xxx.html', load_timeout=10, tries=1)  
except spynner.SpynnerTimeout:  
        print 'Timeout.'  
else:  

        browser.wk_click('a[id="voteProjectBtn_10353150"]', wait_load=True)  
browser.close()  

我正在使用 Python 2.7,感谢您的帮助!

4

1 回答 1

-1

before browser.close(),你必须distroy循环javascript,有些网站有定时脚本,所以你需要distroy这些脚本见browser.py,改变方法“_manager_create_request”,before browser.close(),设置self.closeflag = True

def _manager_create_request(self, operation, request, data):
    if self.closeflag:
        return None
    url = unicode(request.url().toString())
    operation_name = self._operation_names[operation].upper()
    self._debug(INFO, "Request: %s %s" % (operation_name, url))
    for h in request.rawHeaderList():
        self._debug(DEBUG, "  %s: %s" % (h, request.rawHeader(h)))
    if self._url_filter:
        if self._url_filter(self._operation_names[operation], url) is False:
            self._debug(INFO, "URL filtered: %s" % url)
            request.setUrl(QUrl("about:blank"))
        else:
            self._debug(DEBUG, "URL not filtered: %s" % url)
    reply = QNetworkAccessManager.createRequest(self.manager,
        operation, request, data)
    return reply
于 2015-11-27T03:40:35.147 回答