Search code examples
pythonbeautifulsoupevent-listenerhtml-tbody

How to parsh event listener <tbody> by bs4?


This code showing table empty but it is not because web page filling table with help of some js code.

So I don't know how to parsh it. Please tell me how to parsh it.

import bs4 as bs
import urllib.request

source = urllib.request.urlopen('https://monerobenchmarks.info/').read()
soup = bs.BeautifulSoup(source,'lxml')

table = soup.find('table')
table_rows = table.find_all('tr')
for tr in table_rows:
    td = tr.find_all('td')
    row = [i.text for i in td]
    print(row)

Solution

  • To use selenium with bs4, try chrome or Firefox driver

    from bs4 import BeautifulSoup as Soup
    
    from selenium import webdriver
    
    driver = webdriver.Chrome()
    driver.get("https://monerobenchmarks.info/")
    
    page = Soup(driver.page_source, features='html.parser')
    
    table = page.find('table')
    table_rows = table.find_all('tr')
    for tr in table_rows:
        td = tr.find_all('td')
        row = [i.text for i in td]
        print(row)