From: Lennart Borgman <lennart.borgman@gmail.com>
To: Thamer Mahmoud <thamer.mahmoud@gmail.com>
Cc: help-gnu-emacs@gnu.org
Subject: Re: How to get title of web page by url?
Date: Wed, 28 Jul 2010 17:44:45 +0200 [thread overview]
Message-ID: <AANLkTi=ueFLP3JpAC5U9R5LL97NF7Hi03dkWho_ccJ9q@mail.gmail.com> (raw)
In-Reply-To: <87ocdr39i7.fsf@zemblan.newkuwait.org>
On Wed, Jul 28, 2010 at 5:34 PM, Thamer Mahmoud
<thamer.mahmoud@gmail.com> wrote:
> filebat Mark <filebat.mark@gmail.com> writes:
>
>> Thanks, Thamer. It works.
>>
>> Below is the code snippet.
>>
>> Well, I still have an encoding problem.
>> To get the title of "http://www.baidu.com", the title we get is displayed as
>> unrecognizable codes.
>>
>> I have tried to encode it, in the way of "(setq web_title_str
>> (encode-coding-string web_title_str 'utf-8-dos))", but it fails.
>
> I'm also new to Elisp (well sort of).
>
> But here is a modified version that should handle both charsets and
> newlines (and other issues noticed by Deniz Dogan. Thanks).
>
> (defun www-get-page-title (url)
> (let ((title))
> (with-current-buffer (url-retrieve-synchronously url)
> (goto-char (point-min))
> (re-search-forward "<title>\\([^<]*\\)</title>" nil t 1)
> (setq title (match-string 1))
> (goto-char (point-min))
> (re-search-forward "charset=\\([-0-9a-zA-Z]*\\)" nil t 1)
> (decode-coding-string title (intern (match-string 1))))))
>
> The robustness of this code would still depend on whether the HTML is
> well-formed, but it should be good enough I think.
Have a look at url-copy-file for how to get this correct. (Or
web-vcs-url-copy-file in nXhtml which is a little bit more careful.)
next prev parent reply other threads:[~2010-07-28 15:44 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-07-27 12:14 How to get title of web page by url? filebat Mark
2010-07-28 5:08 ` Thamer Mahmoud
2010-07-28 13:44 ` filebat Mark
2010-07-28 15:34 ` Thamer Mahmoud
2010-07-28 15:44 ` Lennart Borgman [this message]
2010-07-28 18:14 ` Thamer Mahmoud
2010-07-29 15:07 ` filebat Mark
2010-07-28 14:12 ` Deniz Dogan
2010-07-28 14:53 ` Teemu Likonen
2010-07-28 16:03 ` Andreas Röhler
2010-07-28 19:52 ` Andreas Röhler
[not found] ` <mailman.2.1280326418.17798.help-gnu-emacs@gnu.org>
2010-07-28 14:49 ` Ted Zlatanov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='AANLkTi=ueFLP3JpAC5U9R5LL97NF7Hi03dkWho_ccJ9q@mail.gmail.com' \
--to=lennart.borgman@gmail.com \
--cc=help-gnu-emacs@gnu.org \
--cc=thamer.mahmoud@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).