Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # How to extract paragraph from a website and save it as a text file?
- import urllib.request
- from bs4 import BeautifulSoup
- # here we have to pass url and path
- # (where you want to save ur text file)
- urllib.request.urlretrieve("https://www.geeksforgeeks.org/grep-command-in-unixlinux/?ref=leftbar-rightbar",
- "/home/skip420/Desktop/scrape_Job/notes.txt")
- file = open("notes.txt", "r")
- contents = file.read()
- soup = BeautifulSoup(contents, 'html.parser')
- f = open("products.txt", "w")
- # traverse paragraphs from soup
- for data in soup.find_all("p"):
- sum = data.get_text()
- f.writelines(sum)
- f.close()
Add Comment
Please, Sign In to add comment