кодесурса
«Python

Python Web Scraping: отображение содержимого различных атрибутов указанного ресурса.

script1adsense2code
script1adsense3code

Python Web Scraping: Упражнение 26 с решением

Напишите программу на Python для отображения содержимого различных атрибутов, таких как код_состояния, заголовки, URL, история, кодировка, причина, файлы cookie, истекшее время, запрос и содержимое указанного ресурса.

Пример решения : -

Код Python:

import requests
response = requests.get('https://python.org')
print("Status Code: ",response.status_code)
print("Headers: ",response.headers)
print("Url: ",response.url)
print("History: ",response.history)
print("Encoding: ",response.encoding)
print("Reason: ",response.reason)
print("Cookies: ",response.cookies)
print("Elapsed: ",response.elapsed)
print("Request: ",response.request)
print("Content: ",response._content)
  
 

Выход

 Код статуса: 200
Заголовки: {'Server': 'nginx', 'Content-Type': 'text / html; charset = utf-8 ',' X-Frame-Options ':' DENY ',' Via ':' 1.1 vegur, 1.1 лак, 1.1 лак ',' Content-Length ':' 49144 ',' Accept-Ranges ': 'bytes', 'Date': 'Fri, 07 Jun 2019 09:13:20 GMT', 'Age': '1021', 'Connection': 'keep-alive', 'X-Served-By': 'cache -iad2145-IAD, cache-bom18222-BOM ',' X-Cache ':' HIT, HIT ',' X-Cache-Hits ':' 2, 26 ',' X-Timer ':' S1559898800.373555, VS0 , VE0 ',' Vary ':' Cookie ',' Strict-Transport-Security ':' max-age = 63072000; IncludeSubdomains'}
URL: https://www.python.org/
История: [<Response [301]>]
Кодировка: utf-8
Причина: хорошо
Cookies: <RequestsCookieJar []>
Прошло: 0: 00: 00.280475
Запрос: <PreparedRequest [GET]>
Содержание: b '<! Doctype html> / n <! - [if lt IE 7]> <html class = "no-js ie6 lt-ie7 lt-ie8 lt-ie9"> <! [Endif] -> / n <! - [if IE 7]> <html class = "no-js ie7 lt-ie8 lt-ie9"> <! [endif] -> / n <! - [if IE 8]> < html class = "no-js ie8 lt-ie9"> <! [endif] -> / n <! - [if gt IE 8]> <! -> <html class = "no-js" lang = "en" dir = "ltr"> <! - <! [endif] -> / n / n <head> / n   
........
  </ div> / n / n </ div> <! - end .container -> / n </ div> <! - end .site-base -> / n / n </ footer> / n / n </ div> <! - end # touchnav-wrapper -> / n / n / n <script src = "// ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min .js "> </ script> / n <script> window.jQuery || document.write (/ '<script src = "/ static / js / libs / jquery-1.8.2.min.js"> </// script> /') </ script> / n / n <script src = "/static/js/libs/masonry.pkgd.min.js"></script>/n <script src =" / static / js / libs / html-includes.js "> </ script> / n / n <script type = "text / javascript" src = "/ static / js / main-min.fbfe252506ae.js" charset = "utf-8"> </ script> / n / n / n <! - [if lte IE 7]> / n <script type = "text / javascript" src = "/ static / js / plugins / IE8-min.16868e6a5d2f.js" charset = "utf-8"> </ script> / n / n / n <! [endif] -> / n / n <! - [if lte IE 8]> / n <script type = "text / javascript" src = "/ static / js / plugins / getComputedStyle-min.c3860be1d290 .js "charset =" utf-8 "> </ script> / n / n / n <! [endif] -> / n / n / n / n / n / n / n </ body> / n < / html> / п»

Блок - схема:

«Python

Редактор кода Python:


Есть другой способ решить это решение? Внесите свой код (и комментарии) через Disqus.

Предыдущий: Напишите программу на Python, чтобы получить число землетрясений магнитудой 4,5+, обнаруженных Геологической службой США во всем мире.
Далее: Напишите программу на Python для проверки SSL-сертификатов для HTTPS-запросов с использованием модуля запросов.

Каков уровень сложности этого упражнения?

Новый контент: Composer: менеджер зависимостей для PHP , R программирования


script1adsense4code
script1adsense5code
disqus2code
script1adsense6code
script1adsense7code
script1adsense8code
buysellads2code