python - Web Scraping - blank return -
could please explain me why blank return when running code? trying print contents of html tag using beautiful soup. code below.
thanks
import urllib3 urllib3.disable_warnings(urllib3.exceptions.insecurerequestwarning) bs4 import beautifulsoup http = urllib3.poolmanager() def stats(): url = 'https://www.flashscore.com.au/football/usa/mls/results/' response = http.request('get', url) soup = beautifulsoup(response.data,'lxml') right_table=soup.find('div',{'class':'fs-table tournament-page'}) print(right_table.text) stats()
you can fetch , process multiple urls using pyqt5 ask in comment this:
from pyqt5.qtgui import * pyqt5.qtcore import * pyqt5.qtwebkit import * pyqt5.qtwebkitwidgets import qwebpage pyqt5.qtwidgets import qapplication import bs4 bs import sys class render(qwebpage): def __init__(self): super(render, self).__init__() self.mainframe().loadfinished.connect(self.handleloadfinished) def start(self, urls): self._urls = iter(urls) self.fetchnext() def fetchnext(self): try: url = next(self._urls) except stopiteration: return false else: self.mainframe().load(qurl(url)) return true def processcurrentpage(self): print (self.mainframe().url().tostring()) result = self.mainframe().tohtml() soup = bs.beautifulsoup(result, 'lxml') right_table = soup.find('div', {'class': 'fs-table tournament-page'}) print(right_table.text) def handleloadfinished(self): self.processcurrentpage() if not self.fetchnext(): app.quit() if __name__ == '__main__': urls = ["https://www.flashscore.com.au/football/usa/mls/results/", "https://www.flashscore.com.au/football/usa/mls/fixtures/"] app = qapplication(sys.argv) renderer = render() renderer.start(urls) sys.exit(app.exec_())
Comments
Post a Comment