我很努力地使用QWebElement。作爲一項練習,我想從第http://www.google.com頁獲取「Google」徽標。該圖像位於<div id="hplogo" ...>
,但我不知道如何提取它。我如何在下面的代碼中使用「doc」QWebElement? (「CSS選擇器」對我來說是個晦澀的術語)。 謝謝。使用QWebElement解析HTML,如何提取圖像?
from PyQt4.QtGui import QApplication
from PyQt4.QtWebKit import QWebView
from PyQt4.QtCore import QUrl
app = QApplication([])
view = QWebView()
view.load(QUrl("http://google.com"))
view.show()
doc = view.page().currentFrame().documentElement() # run this after 'loadFinished'
對不起,這是一個廢話,但複製粘貼您的代碼似乎不起作用。我試圖解釋它,並設法從'imgURL = doc.findFirst(「img」)。attribute(「src」)'獲得一個QString,其值等於'/ images/icons/product/chrome-48。 png''。但是我在下一步努力......我如何訪問這個字符串應該指向的圖像? QImage()。load(imgURL)返回False。 – Olivier
預先安裝基本URL。 「http://google.com/images/icons/product/chrome-48.png」應該可以工作。我編輯了我的答案。 –
它似乎沒有與prepended鏈工作(我寧願不再下載一個剛下載的圖像)。 – Olivier