How to extract the data from from the html?
from urllib.request import urlopen
url = 'http://book.ponniyinselvan.in/part-1/chapter-1.html'
page = urlopen(url)
getting HTTPError: HTTP Error 403: Forbidden
I am trying to extract the data into CSV file.
You can use this example how to save the text into a CSV file:
import csv
import requests
from bs4 import BeautifulSoup
url = "http://book.ponniyinselvan.in/part-1/chapter-1.html"
with open("data.csv", "w") as f_out:
writer = csv.writer(f_out)
soup = BeautifulSoup(requests.get(url).content, "html.parser")
text = soup.section.get_text(strip=True, separator="\n")
writer.writerow(["Chapter", "Text"])
writer.writerow([1, text])
Saves data.csv
(screenshot from LibreOffice):
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.