티스토리 뷰

공부

[pandas] web scraping

승가비 2022. 8. 13. 02:08
728x90
pip install lxml html5lib beautifulsoup4
import pandas as pd

url = 'https://en.wikipedia.org/wiki/History_of_Python'
dfs = pd.read_html(url)

print(len(dfs))
print(dfs[0]['Version'])
print(dfs[0]['Release date'])
# Load pandas

import pandas as pd

# Webpage url                                                                                                               
url = 'https://en.wikipedia.org/wiki/History_of_Python'

# Extract tables
dfs = pd.read_html(url)

# Get first table                                                                                                           
df = dfs[0]

# Extract columns                                                                                                           
df2 = df[['Version','Release date']]
print(df2)
# Write to excel
df2.to_excel('python.xlsx')

https://pythonbasics.org/pandas-web-scraping/

 

Pandas Web Scraping - Python Tutorial

Pandas makes it easy to scrape a table ( tag) on a web page. After obtaining it as a DataFrame, it is of course possible to do various processing and save it as an Excel file or csv file. In this article you’ll learn how to extract a table from any webpa

pythonbasics.org

 

728x90
댓글
댓글쓰기 폼