2012-02-15 2 views
-1

Я использую HTTP :: Request для получения заголовка корня xml, но когда я печатаю тег или поле заголовка, он печатает пустую строку.Как получить заголовок страницы html

use HTTP::Request; 
    use LWP::UserAgent; 

    my $ua = LWP::UserAgent->new; 
    my $request = HTTP::Request->new(GET => 'http://www.gmail.com'); 

    print "Requesting...\n"; 
    my $response = $ua->request($request); 
    print " Status: ", $response->status_line, "\n"; 
    print " Last modified: ", $response->header('last-modified'), "\n"; 
    print " Etag: ", $response->header('etag'), "\n\n"; 

Есть, любой способ, чтобы получить, в последний раз веб-страница модифицируется, которые не имеют меток, как «последнее изменение» и «ETAG»?

+0

Возможно, это не отправка этага? –

ответ

1

Кажется, что этот конкретный сайт не возвращает etag или last-modified заголовок ключа.

Вы можете просто получить все вещи с dump:

my $request = HTTP::Request->new(GET => 'http://www.gmail.com'); 
my $response = $ua->request($request); 
print $response->dump()."\n"; 

И вы получите:

HTTP/1.1 200 OK 
Cache-Control: no-cache, no-store 
Connection: close 
Date: Wed, 15 Feb 2012 18:55:54 GMT 
Pragma: no-cache 
Server: GSE 
Content-Type: text/html; charset=UTF-8 
Expires: Mon, 01-Jan-1990 00:00:00 GMT 
Client-Date: Wed, 15 Feb 2012 18:55:53 GMT 
Client-Peer: 173.194.67.84:443 
Client-Response-Num: 1 
Client-SSL-Cert-Issuer: /C=ZA/O=Thawte Consulting (Pty) Ltd./CN=Thawte SGC CA 
Client-SSL-Cert-Subject: /C=US/ST=California/L=Mountain View/O=Google Inc/CN=accounts.google.com 
Client-SSL-Cipher: RC4-SHA 
Client-SSL-Socket-Class: IO::Socket::SSL 
Client-Transfer-Encoding: chunked 
Link: <//mail.google.com/favicon.ico>; rel="icon"; type="image/ico" 
Link: <https://plus.google.com/103345707817934461425>; rel="publisher" 
Set-Cookie: GAPS=1:P5tYXkr9cvVAMBJZ_j8lm34_tvxOWQ:Wt3iF5PQ_mn8YVOj;Path=/;Expires=Fri, 14-Feb-2014 18:55:54 GMT;Secure;HttpOnly 
Set-Cookie: GALX=N9ISXky4Eu8;Path=/;Secure 
Strict-Transport-Security: max-age=2592000; includeSubDomains 
Title: Gmail: Email from Google 
X-Auto-Login: realm=com.google&args=service%3Dmail%26continue%3Dhttp%253A%252F%252Fmail.google.com%252Fmail%252F 
X-Content-Type-Options: nosniff 
X-Frame-Options: Deny 
X-Meta-Charset: utf-8 
X-Meta-Description: 7+ GB of storage, less spam, and mobile access. is email that's intuitive, efficient, and useful. And maybe even fun. 
X-XSS-Protection: 1; mode=block 

<!DOCTYPE html> 
<html lang="en"> 
    <head> 
    <meta charset="utf-8"> 
    <title>Gmail: Email from Google</title> 
    <meta name="description" content="7+ GB of storage, less spam, and mobile access. is email that&#39;s intuitive, efficient, and useful. And maybe even fun."> 
    <link rel="icon" type="image/ico" href="//mail.google.com/favicon.ico"> 
<style type="text/css"> 
    html, body, div, h1, h2, h3, h4, h5, h6, p, img, dl, 
    dt, dd, ol, ul, li, table, tr, td, form, object, embed, 
    article, aside, canvas, comma... 
(+ 54500 more bytes not shown) 

... и нет etag, ни last-modified.

Смежные вопросы