From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Yuri Khan Newsgroups: gmane.emacs.help Subject: Re: To fetch URL, extract element? Date: Thu, 12 Nov 2020 21:49:47 +0700 Message-ID: <CAP_d_8VupQ5p1s_F=zmhSogs7XZmbLnFr51T6qUjayns0PT57g@mail.gmail.com> References: <X6uupXrgbwdITVW4@protected.rcdrun.com> <87zh3nc3r4.fsf@web.de> <X6wntvKmc5LtYuiO@protected.rcdrun.com> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="1131"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Michael Heerdegen <michael_heerdegen@web.de>, help-gnu-emacs <help-gnu-emacs@gnu.org> To: Jean Louis <bugs@gnu.support> Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Thu Nov 12 15:53:54 2020 Return-path: <help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org> Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from <help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org>) id 1kdDyz-0000DL-O4 for geh-help-gnu-emacs@m.gmane-mx.org; Thu, 12 Nov 2020 15:53:53 +0100 Original-Received: from localhost ([::1]:37882 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from <help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org>) id 1kdDyy-0007Ln-FP for geh-help-gnu-emacs@m.gmane-mx.org; Thu, 12 Nov 2020 09:53:52 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:42424) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <yurivkhan@gmail.com>) id 1kdDvK-0004Kj-4n for help-gnu-emacs@gnu.org; Thu, 12 Nov 2020 09:50:06 -0500 Original-Received: from mail-vk1-xa29.google.com ([2607:f8b0:4864:20::a29]:41143) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <yurivkhan@gmail.com>) id 1kdDvI-0006ag-4f for help-gnu-emacs@gnu.org; Thu, 12 Nov 2020 09:50:05 -0500 Original-Received: by mail-vk1-xa29.google.com with SMTP id e8so1365518vkk.8 for <help-gnu-emacs@gnu.org>; Thu, 12 Nov 2020 06:50:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=srb83tj2hJn/Ogf/knpeim63TMdIjT/tJqu4ARNL9XI=; b=hbsqZDRkANluk0W51pjp0HVX2cPss3nfEjw/BCmibqTjO7yIpfnrmvt3mHli7MfXMt t2+Dd17A/xaMHxdWtFChDfl3MEElKBgu1Qt9jow/jwYvCyI4q5FgVQUdQWGW2c3hW6OS oEuxjm7PKYhxh6k/OUX6aYlNlrNiBRl/oUix5Dq4u/bQkr/tSWMJLtOdkA7wQE/6Fs2C KGMWJ/Cc2Tf/yqY9l59l+Nc+OjaWqkpK3Yoefva9FlZaSC+wBZ1nscN2JkoPLXEhVJPh B69qNxjxofcy5Pdy6jW2qawvWlIvpiKTuFBm2xSobydnc22KsyMqvn/O7NFUte4WVSxA /Tyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=srb83tj2hJn/Ogf/knpeim63TMdIjT/tJqu4ARNL9XI=; b=ufMMunaimLYcPS1govTOv0Y+UHzWU6dOfhEwPMN6yLuqZ2FMFHaAapCJHTcSfxnaa2 3psUFVlTbRsvkrMBlRepl/bu9IEBgMiXYNGuMiEHUzozyI5n092Jxy20HdDGwfFNKanT JV+5gCFaADfwcWtPoTHs0EYCOxSXpV/xhlfyb0kHZEyehzt1PRupciKLBEOx57o6F7ew mm0JpNw+hflozPt69WCaa4LD/Wxo+nkUM+bTKm1JSx/uPE2fggWC8X4U4tb+Zp0cm8E8 OhYlhEglYKCAsOQX4DMwfMmPVJ2+W/YC+BwBpbLqNZCGm/qAz/n7y4xwVzuL+aaIZ8hP gXOw== X-Gm-Message-State: AOAM530XnRDm5pL9gmhDCM8tIAtsFOrmDB3ub7I14TxxGqNpMBBok/z0 oeSxJToUsAgYhClMU5fAYpX53AILAAr4BPKAR3E= X-Google-Smtp-Source: ABdhPJyr0TZFNnGSqJ7ppPElqvGVtJKlFEai4xP9tuiYBTMTAYytgreF3n22tdAJfCOfPcqWbdwavXXEmWE5NTbQH2I= X-Received: by 2002:a1f:2389:: with SMTP id j131mr117766vkj.18.1605192600321; Thu, 12 Nov 2020 06:50:00 -0800 (PST) In-Reply-To: <X6wntvKmc5LtYuiO@protected.rcdrun.com> Received-SPF: pass client-ip=2607:f8b0:4864:20::a29; envelope-from=yurivkhan@gmail.com; helo=mail-vk1-xa29.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Users list for the GNU Emacs text editor <help-gnu-emacs.gnu.org> List-Unsubscribe: <https://lists.gnu.org/mailman/options/help-gnu-emacs>, <mailto:help-gnu-emacs-request@gnu.org?subject=unsubscribe> List-Archive: <https://lists.gnu.org/archive/html/help-gnu-emacs> List-Post: <mailto:help-gnu-emacs@gnu.org> List-Help: <mailto:help-gnu-emacs-request@gnu.org?subject=help> List-Subscribe: <https://lists.gnu.org/mailman/listinfo/help-gnu-emacs>, <mailto:help-gnu-emacs-request@gnu.org?subject=subscribe> Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "help-gnu-emacs" <help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org> Xref: news.gmane.io gmane.emacs.help:125250 Archived-At: <http://permalink.gmane.org/gmane.emacs.help/125250> On Thu, 12 Nov 2020 at 01:05, Jean Louis <bugs@gnu.support> wrote: > > > What is the standard built-in way to fetch the http[s] URL? > > > > `url-retrieve' sounds appropriate. > > I am trying like this: > > (defun wrs-fetch-title (url) > (url-retrieve url #'wrs-get-title (list url))) > > (defun wrs-get-title (status url) > (message-any status)) > > (wrs-fetch-title "http://localhost") > > At least I get status nil, but I do not know how to get the HTML > text. Have you read the docstring of =E2=80=98url-retrieve=E2=80=99? CALLBACK is called when the object has been completely retrieved, with the current buffer containing the object, and any MIME headers associat= ed with it.[=E2=80=A6] So probably: (defun wrs-fetch-title (url) (url-retrieve url #'wrs-get-title (list url))) (defun wrs-get-title (status url) (goto-char (point-min)) (search-forward "\n\n") ; skip HTTP headers (if (search-forward-regexp "<title\\(?:\\s+[^>]*\\)?>\\([^<]*\\)" nil 'noerror) (message "URL: %s Title: %s" url (match-string 1)))) (wrs-fetch-title "https://gnu.org/") =E2=87=92 URL: https://gnu.org/ Title: The GNU Operating System and the Fre= e Software Movement (For demonstration purposes, I=E2=80=99m overlooking error handling and MIM= E type checks. In a real program, you ought to first make sure you got a successful status, then check that the response you got has a =E2=80=98Content-Type=E2=80=99 of either =E2=80=98text/html=E2=80=99 or =E2= =80=98application/xhtml+xml=E2=80=99 (with possible parameters such as =E2=80=98charset=E2=80=99), and only then look = for HTML-specific =E2=80=A6 tags.)