Jump to content
Fórum Script Brasil
  • 0

Obter headers de paginas com python


wyohara
 Share

Question

Estou fazendo um programa em python para capturar dados de paginas da web e extrair dados de interesse,  mas eu estou com um serio problema: não quero ficar baixando as paginas toda toda hora para poder comparar. Quero usar o headers e comparar as datas dada por "last-modified:".

Tentei usar o urllib mas quando dou info() só aparece os dados gerais não mostra o header.

import urllib.request
site='http://www.evcomp.dcc.ufmg.br/?q=pt-br'
#criando headers de identificação
head = {}
head['User-Agent'] = "Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.27 Safari/537.17"
#Requerendo conexão
req = urllib.request.Request(site, headers = head)
#obtendo resposta
resp = urllib.request.urlopen(req)
#leitura do site
print(resp.info())

Resultado:

>>> 
Date: Wed, 14 Oct 2015 01:44:57 GMT
Server: Apache/2.2.22 (Ubuntu)
X-Powered-By: PHP/5.3.10-1ubuntu3.20
Expires: Sun, 19 Nov 1978 05:00:00 GMT
Cache-Control: no-cache, must-revalidate, post-check=0, pre-check=0
Content-Language: pt-br
X-Generator: Drupal 7 (http://drupal.org)
Vary: Accept-Encoding
Connection: close
Transfer-Encoding: chunked
Content-Type: text/html; charset=utf-8

Peço ajuda para resolver isso. Grato.

 

Link to comment
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Forum Statistics

    • Total Topics
      149.6k
    • Total Posts
      646.2k
×
×
  • Create New...