我在刮擦赛马场时遇到了麻烦,似乎阅读页面的速度太快了,只是返回“正在加载...。”
这是我的代码:
import sys
from PyQt4.QtGui import QApplication
from PyQt4.QtCore import QUrl
from PyQt4.QtWebKit import QWebPage
import bs4 as bs
import urllib.request
class Client(QWebPage):
def __init__(self, url):
self.app = QApplication(sys.argv)
QWebPage.__init__(self)
self.loadFinished.connect(self.on_page_load)
self.mainFrame().load(QUrl(url))
self.app.exec_()
def on_page_load(self):
self.app.quit()
url = 'https://www.racenet.com.au/racing-form-guide/ballina-20181126/tab-com-au-maiden-plate-race-2/form'
client_response = Client(url)
source = client_response.mainFrame().toHtml()
soup = bs.BeautifulSoup(source, 'lxml')
js_test = soup.find('table', class_='form-table col-md-12')
print(js_test.text)
输出:
Loading....