Python Forum

Full Version: How do I scrape a web page?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
All:
I want to scrape this web-page using Python, but specifically I want to retrieve the data that I've indicated below:
Here's the webpage:
https://www.baseball-reference.com/teams...ders.shtml

The specific data is located about 2/3 of the way down the page and has the title "Most Common Batting Orders".
I need the data from the first column:
Rose
Griffey
Morgan
Bench
Perez
Geronimo
Concepcion
Foster
Pitcher


Thanks is advance.
most of this page is rendered from JavaScript, so you must use a scraping tool that will expand the JavaScript before searching for the table. This is best done using selenium.

run through the web scraping tutorials on this forum here (only takes a few hours):
web scraping part 1
web scraping part 2

Selenium is covered in part 2, but running through part 1 would be beneficial.
You can use the Python module selenium to scrape this web page. Selenium will starts your browser and interact with it through Python. Selenium needs a driver, if you use Firefox you need GeckoDriver and for Chrome you need ChromeDriver.

Then you can start it like so

from selenium import webdriver
 
driver = webdriver.Firefox()
driver.get("https://dev.to")
and find the element by id or name

You can find the element id in html, the table has the id "id="grid_table_642496". Then it would be

element=browser.find_element(By.ID,"grid_table_642496")
from there grab the data you need