首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用PyQT QWebElement提交谷歌

使用PyQT QWebElement提交谷歌
EN

Stack Overflow用户
提问于 2010-09-13 01:26:54
回答 1查看 1.8K关注 0票数 0

以下代码未到达searchResults。我已经打印出了documentElement.findFirst('inputname="btnG"'),并且发现它是<input name="btnG" type="submit" value="Google Search" class="lsb">,所以我们在这一点上是很好的。请注意,我的目标不是刮刮谷歌,而是通过知名的公共谷歌来学习更简单。

代码语言:javascript
复制
#!/usr/bin/python
from PyQt4.QtCore import QUrl, SIGNAL
from PyQt4.QtGui import QApplication
from PyQt4.QtWebKit import QWebPage, QWebView

class Scrape(QApplication):
  def __init__(self):
    super(Scrape, self).__init__(None)
    self.webView = QWebView()
    self.webView.loadFinished.connect(self.searchForm)

  def load(self, url):
    self.webView.load(QUrl(url))

  def searchForm(self):
    documentElement = self.webView.page().currentFrame().documentElement()
    inputSearch = documentElement.findFirst('input[title="Google Search"]')
    inputSearch.setAttribute('value', 'test')
    self.webView.loadFinished.disconnect(self.searchForm)
    self.webView.loadFinished.connect(self.searchResults)
    documentElement.findFirst('input[name="btnG"]').evaluateJavaScript('click()')

  def searchResults(self):
    for element in documentElement.find('li[class="g"]'):
      print unicode(element.toOuterXml())
    self.exit()

my_scrape = Scrape()
my_scrape.load('http://google.com/ncr')
my_scrape.exec_()
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2010-09-13 04:38:08

我终于想通了!并提交给http://drupal4hu.com/node/266

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3695781

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档