How could I use Sockets package to get part of HTML file?

zakyn's picture

Hello,

I would like to use Socket package to get informaction from HTML page on Website. COuld you help me please? I need to get the part of HTML file to use it in my procedure.

Thank you very much

Vladimir

Comments

JacquesC's picture

Ask tech support

Since you have not had an answer here, ask tech support. I am fairly sure I have seen such things done, but it is not so obvious how to put all the tools together (unlike what you can do in Python or Perl, where this is trivial).

HTTP

Try:

(r, txt) := HTTP[Get]("www.maplesoft.com");

This is in Maple 11, though it's still experimental and thus not documented.

-Laurent

JacquesC's picture

Wonderful

Quite handy. And for the original poster, a little bit of

interface(verboseproc=3); kernelopts(opaquemodules=false);
print(HTTP[Get]);
print(HTTP[SendRequest]); 

gives a nice answer to the original query of how to use Sockets to get the task done.

zakyn's picture

HTTP works

Hello Laurent,

we have met on MARC 2006. Thank you very much, HTTP works. It is very usefull. Is it possible to do that with Socket package?

Thank you.

Vladimir

zakyn's picture

Is there any limitation in HTTP[Get]?

Hello,

I thought, that it works, but if I change URL e.g. to www.maplesoft.cz it does not work. Do you explain me please?

Two examples:

> (r, txt) := HTTP[Get]("www.maplesoft.cz");
r, txt := 200, ""

> (r, txt) := HTTP[Get]("www.vladimirzak.com/maple");

r, txt := 301, "< !DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"\>
<html><head>
<title>301 Moved Permanently</title>
</head><body>
<h1>Moved Permanently</h1>
<p>The document has moved <a href="http://www.vladimirzak.\com/maple/">here</a>.</p>
</body></html>
"

What is wrong? The sites are there.

Thank you very much for your answer.

Vladimir

Axel Vogt's picture

i think you need to add the

i think you need to add the file name (a browser does it automatically
by trying index.htm or index.html)

(r, txt) := HTTP[Get]("http://www.vladimirzak.com/maple/index.html");

not sure what the command would do with the style sheets at your page

zakyn's picture

Why does maplesoft.com work?

Well, www.maplesoft.com works correctly but the other does not work. Why?

Vladimir

Axel Vogt's picture

hm

at least the short docu suggests to use it ...

actually do not know and what would happen if you have 2 files in your root,
one index.htm and one index.htmL and being not quite used with the protocol

but you can try off Maple by opening a DOS prompt and enter various string:

ping http://www.vladimirzak.com/maple
ping http://www.vladimirzak.com

the first does not resolve for a host name, the last does and if i would like
to know the reason, then i would try to read about HTTP

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
}