Scraping data - attributes from a web page

The_elevator

Hello i am new in web scraping and i have a problem. I want to scrape data from this html code: enter image description here

I want to have the data that belongs inside the

<tr> .. </tr> 

tag.

My code is shown as below:

from bs4 import BeautifulSoup
import requests

html_text = requests.get('https://www.basketball-reference.com/leagues/').text
soup = BeautifulSoup(html_text, 'lxml')
rows = soup.select('tr[data-row]')

print(rows)

I am inspired by this thread, but it's returning a empty array. Can anyone help me with this

baduker

How about using pandas to make your web-scraping life (a bit) easier?

Here's how:

import pandas as pd
import requests

df = pd.read_html(requests.get('https://www.basketball-reference.com/leagues/').text, flavor="bs4")
df = pd.concat(df)
df.to_csv("basketball_table.csv", index=False)

Output:

enter image description here

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related