How to resolve the algorithm Web scraping step by step in the M2000 Interpreter programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Web scraping step by step in the M2000 Interpreter programming language

Table of Contents

Problem Statement

Create a program that downloads the time from this URL:   http://tycho.usno.navy.mil/cgi-bin/timer.pl   and then prints the current UTC time by extracting just the UTC time from the web page's HTML. Alternatively, if the above url is not working, grab the first date/time off this page's talk page.

If possible, only use libraries that come at no extra monetary cost with the programming language and that are widely available and popular such as CPAN for Perl or Boost for C++.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Web scraping step by step in the M2000 Interpreter programming language

Source code in the m2000 programming language

Module Web_scraping {
	Print "Web scraping"
	function GetTime$(a$, what$="UTC") {
		document a$ ' change string to document
		find a$, what$  ' place data to stack
		Read find_pos
		if find_pos>0 then
			read par_order, par_pos
			b$=paragraph$(a$, par_order)
			k=instr(b$,">")
			if k>0 then if k
			k=rinstr(b$,"<")
			if k>0 then if k>par_pos then b$=Left(b$,k-1)
			=b$
		end if
	}
	declare msxml2 "MSXML2.XMLHTTP.6.0"
	rem print type$(msxml2)="IXMLHTTPRequest"
	Url$ = "http://tycho.usno.navy.mil/cgi-bin/timer.pl"
	try ok {
		method msxml2, "Open", "GET", url$, false
		method msxml2,"Send"
		with msxml2,"responseText" as txt$
		Print GetTime$(txt$)
	}
	If error or not ok then Print Error$
	declare msxml2 nothing
}
Web_scraping

  

You may also check:How to resolve the algorithm Galton box animation step by step in the Elm programming language
You may also check:How to resolve the algorithm Tic-tac-toe step by step in the Delphi programming language
You may also check:How to resolve the algorithm Write entire file step by step in the Smalltalk programming language
You may also check:How to resolve the algorithm Cholesky decomposition step by step in the Phix programming language
You may also check:How to resolve the algorithm Babbage problem step by step in the Quackery programming language