Using Python I'd like to scrape some information from a webpage and save the info to a .txt file named using the title of the page scraped.
Unfortunately many pages contain special characters that can't be used in file names, so ideally I want to extract the title you would get if you did file/save from a browser.
Is it possible to achieve this with BeautifulSoup or Selenium?
I can get the page title with soup, and then clean it, but if there is a more efficient way of getting the browser-cleaned title I'd love to know how.
EDIT:
So far I have achieved a workable result with the following code. I used YouTube as an example but really would prefer an all-purpose page-title retrieval in browser save format if possible. Probably doesn't exist, but there's always hope.
import re
import mechanize
br = mechanize.Browser()
br.open("https://www.youtube.com/watch?v=RvCBzhhydNk")
title = re.sub('[^A-Za-z0-9]+', ' ', br.title().replace("YouTube", "")).strip()
print(title)