1

I need to kill and yank some portion of the source code of multiples websites for a database i'm making of news of certain web. But the problem is, whenever i call eww-view-source for viewing the website's source, it gives me an error of "no source".

The function and macro (I made a keyboard macro when the function didn't work) works the first time, but at a second execution it gives me the error.

I'm using an .org file with all the links i need to access and copy a portion from their source. This region is determined with two search-forward expressions. This is the function i made (ignore the name and description, i'm from Latinoamérica):

 (defun aporrea-listar-archivo ()
  "Copia en la entrada el código relativo a las noticias 
de una página del archivo de aporrea."
  (interactive)
  (save-excursion
    (org-open-at-point)
    (set-buffer "*eww*") ;;added this trying to solve
    (eww-view-source)
    (set-buffer "*eww-source*")   ;;added this trying to solve
    (copy-region-as-kill (search-forward "<h1>Noticias</h1>")
             (search-forward "<h1>Artículos de Opinión</h1>"))
    (View-quit)  ;; This exits the view-mode of eww for sources
    (kill-buffer "*eww-source*")
    (kill-buffer "*eww*")))

For some reason the save-excursion is not working. I'm ok with that...

1

Try using eww-after-render-hook. e.g.:

(defun aporrea-listar-archivo ()
  "Copia en la entrada el código relativo a las noticias 
de una página del archivo de aporrea."
  (interactive)
  (save-excursion
    (org-open-at-point)
    (set-buffer "*eww*") ;;added this trying to solve
    (add-hook 'eww-after-render-hook
              (lambda ()
                (eww-view-source)
                (set-buffer "*eww-source*")   ;;added this trying to solve
                (copy-region-as-kill (search-forward "<h1>Noticias</h1>")
                                     (search-forward "<h1>Artículos de Opinión</h1>"))
                (View-quit)  ;; This exits the view-mode of eww for sources
                (kill-buffer "*eww-source*")
                (kill-buffer "*eww*"))
              nil :local)))

Although, as best I can see you have no interest in the rendered HTML at all, so I can't see a reason to use eww for this. Perhaps something like the following meets your needs?

(url-retrieve
 (url-get-url-at-point)
 (lambda (status)
   (copy-region-as-kill (search-forward "<h1>Noticias</h1>")
                        (search-forward "<h1>Artículos de Opinión</h1>"))
   (kill-buffer)))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.