Хабр Курсы для всех
РЕКЛАМА
Практикум, Хекслет, SkyPro, авторские курсы — собрали всех и попросили скидки. Осталось выбрать!
с помощью selenium
USERNAME = input('Введите вашу почту: ')
PASSWORD = input('Введите ваш пароль: ')
LOGIN_URL = "***" # Страница Логина
URL = "***" # Страница самого контента для парсинга
session_requests = requests.session()
def parse_one():
# Create payload
payload = {
"email": USERNAME,
"password": PASSWORD
}
# Perform login
result = session_requests.post(LOGIN_URL, data = payload, headers = dict(referer = LOGIN_URL))
# Scrape journal_url
result = session_requests.get(URL, headers = dict(referer = URL))
soup = BeautifulSoup(result.content)If you don’t specify anything, you’ll get the best HTML parser that’s installed. Beautiful Soup ranks lxml’s parser as being the best, then html5lib’s, then Python’s built-in parser(источник)
with open('test.html', 'w') as output_file:
output_file.write(r.text.encode('cp1251'))isinstance(r.text, unicode) # TrueUnicodeEncodeError: 'ascii' codec can't encode characters in position 23-31: ordinal not in range(128). >>> from urllib.request import urlopen
>>> URL = 'http://habrahabr.ru'
>>> page = urlopen(URL)
>>> page.info().get_content_charset()
'utf-8'
>>> charset = page.info().get_content_charset()
>>> document = page.read().decode(charset)
Web Scraping с помощью python