Scrape a value from a web page from within Oracle using utl_http

Let’s say I want to get the current available version of Oracletool..


Create or replace procedure get_ot_version

as

   req                  UTL_HTTP.REQ;
   resp                 UTL_HTTP.RESP;
   matchcount           number;
   string               varchar2(1024);
   version              varchar2(20);
   errmsg               varchar2(1000);

Begin
 
   --
   -- Set the proxy server, if needed.
   -- 
   --utl_http.set_proxy('http://192.168.1.10:8080');
   --
   -- Make the HTTP request
   --
   req := utl_http.begin_request('http://www.oracletool.com');
   utl_http.set_header(req, 'User-Agent', 'Mozilla/4.0');
   --
   -- Loop through the response pieces
   --
   resp := utl_http.get_response(req);
   loop
      utl_http.read_line(resp, string, TRUE);
      --
      -- Look for a line with "Latest version is" in it, and parse out the version string.
      --
      Select instr(string,'Latest version is') into matchcount from dual;
      if (matchcount > 0) then
         Select regexp_replace(string,'.*Latest version is  ','') into string from dual;
         Select regexp_replace(string,' - Released.*','') into version from dual;
         dbms_output.put_line('Version: '||version);
      end if;
   end loop;
Exception
   when utl_http.end_of_body then
      utl_http.end_response(resp);
   when others then
      errmsg := substr(sqlerrm,1,1000);
      dbms_output.put_line('Exception raised during page scrape! '||errmsg);
End;
/

And then..

SQL> Set serveroutput on;
SQL> Exec get_ot_version;
Version: 2.3.3

PL/SQL procedure successfully completed.

🙂

18 thoughts on “Scrape a value from a web page from within Oracle using utl_http

    • בעקבות הכרה בהפחת שעות עבודה(עקב צרידות), האם הדבר יפגע בעובדת היותי חלק מהסכם אופק, או שמא אין קשר בין הדברים?

    • I love checking into the website and seeing a flurry of comments!Judy – Thanks for checking the site! I haven’t had time to write, but finally after a three month absence I wrote about 8-10 posts and then just time delayed them to come out every few days. They are all done now, but I did just post about Doug’s new car. I’ll try to get more posts up after Christmas … surely I’ll be taking some photos!Merry Christmas everyone!

    • Exquisite blog! Do you have any techniques and tips for aspiring writer? I plan to start my own website soon but I’m a little lost everything. Will you suggest the platform from and freedom as WordPress or to go to a pay choice? There are so many options, I don’t know to choose which, hope you can give me some advice. Thank you.

      • &#D2;0;8on&#82172t do any SEO”, which isn’t the case at all, read my comment again and then refer further down to my next comment, where I’ve had to elaborate in the hopes that assumption isn’t made again.Peace out

    • Wow! This can be a single particular of your most helpful blogs We have at any time arrive across on this subject matter. Essentially Wonderful. I am also a specialist within this subject therefore I can fully grasp your tough work.

      • Anna,Thank you for such kind words! Nothing makes me happier than hearing that someone truly enjoyed our mualefftta, especially someone like you who is bound to have very high standards! We look forward to your visits and will always have a sandwich with your name on it!Thank you again!Leigh Ann

      • BDS chapter in Lebanon is planning to protest and boycott NYE-1 tonite, read more here and vote! View This Poll Liked the post? Share it!MoreDiggEmailLike this:LikeBe the first to like

    • It’s amazing how quickly they grow. I clearly remember when I was the age that each of my kids are at now. Its hard to believe that they will be out of the house soon. I don’t even want to say that!

    • David scrive:Politici …. animali da utilizzare per il circo in sostituzione di tigri, leoni, elefanti e quant’altro.Ce li vedrei proprio a saltare nel cerchio di fuoco oppure a fare il trenino con in spalla i loro compagni di merende.Pannella ? Come tutta la sua razza …….. banderuola và dove il vento tiraOn. Zanoni, l’eccezione che conferma la regola ? …. Sperem !

    • Curioso, son los mismos errores que descubrí hace poco en mi blog de Regiosfera, aunque mi blog ya es viejuno (3 años y 600 posts), y con los mismos síntomas que Victor mencionó. Espero refundar regiosfera y otro proyecto y éstos consejos me han dado “luz” para varias cosas que me dan vueltas en mi cabeza.Gracias David y Víctor

Leave a Reply

Your email address will not be published.