PDA

View Full Version : Get the title and keywords from remote url


BOBKUSPE
08-27-2010, 05:36 PM
Hello,

I am trying to get the title and keywords from remote Urls, but there is an error message:

ERROR MESSAGE:

msxml3.dll error '80070057'

The parameter is incorrect.

/GETREMOTEPAGE.ASP, line 33


Could someome give me a bit help?



<% Option Explicit %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title> New Document </title>
</head>

<body>
<form method=GET action="">
<input type="text" name="strLink">
<input type="submit" name="btnSubmit" value="Show">
</form>

<%
Dim show
if request.form("btnSubmit") = Show then
Dim strPage ' holds the page
Dim strDomain ' holds the domain
Dim objXmlHttp ' XML Http object
Dim strHTML ' holds the HTML code of the page
Dim strTitleLength ' holds the length of the title
Dim strBodyLength ' holds the length of the title
Dim strTitle ' holds the title of the page
Dim strStrip ' holds the parts between < >
Dim strWarning ' holds a warning when the page seems to be invalid

'enter the domain on which the page resides
strDomain = request.form("strLink")


' XML routine to get the file
Set objXmlHttp = Server.CreateObject("Msxml2.ServerXMLHTTP")
objXmlHttp.open "GET", strDomain, False
objXmlHttp.send
strHTML = objXmlHttp.responseText
Set objXmlHttp = Nothing

strTitleLength = CInt(instr(lcase(strHTML),"</title>"))-CInt(instr(lcase(strHTML),"<title>")+7)
strBodyLength = CInt(instr(lcase(strHTML),"</body>"))-CInt(instr(lcase(strHTML),"</head>")+7)

' determine whether the page has a valid title
if CInt(instr(lcase(strHTML),"</title>")) = 0 or CInt(instr(lcase(strHTML),"<title>")+7) = 7 then
strTitle = "No Title"
else
strTitle = Mid(strHTML,CInt(instr(lcase(strHTML),"<title>")+7),strTitleLength)
end if

' determine whether the page has a valid body
if CInt(instr(lcase(strHTML),"</body>")) = 0 or CInt(instr(lcase(strHTML),"</head>")+7) = 7 then
strWarning = 1
else
strHTML = Mid(strHTML,CInt(instr(lcase(strHTML),"</head>")+7),strBodyLength)
end if

' ******************** Do the actual stripping ********************
do while CInt(instr(strHTML,"<")) > 0 and CInt(instr(strHTML,">") + 1) > CInt(instr(strHTML,"<"))
strStrip = mid(strHTML,CInt(instr(strHTML,"<")),CInt(instr(strHTML,">") + 1)-CInt(instr(strHTML,"<")))
strHTML = replace(strHTML,strStrip,"")
loop
strHTML = Replace(strHTML, vbCrLf, "")
strHTML = replace(strHTML,"&nbsp;","")
strHTML = replace(strHTML,"<br>","")
Do While InStr(1, strHTML, " " ,vbTextCompare) > 0
strHTML = Replace(strHTML , " ", " ")
Loop
' ********************** The stripping ends **********************

' Give some output
response.write("<font face=""Verdana"" size=""2"" color=""#0000CC"">Title:</font><br>")
response.Write("<font face=""Verdana"" size=""2"" color=""#000000"">" & strTitle & "</font><br>")
response.write("<font face=""Verdana"" size=""2"" color=""#0000CC"">Text Output:</font><br>")
if strWarning = 1 then
response.Write("<font face=""Verdana"" size=""2"" color=""#FF0000"">This seems to be an invalid HTML-file!</font><br>")
end if
response.Write("<font face=""Verdana"" size=""2"" color=""#000000"">" & strHTML & "</font><br>")
end if
%>

</body>
</html>


BOB KUSPE:thumbsup:

Old Pedant
08-27-2010, 07:18 PM
*IF* line 33 is this line:

objXmlHttp.open "GET", strDomain, False

That obviously strDomain is incorrect.

So DEBUG DEBUG DEBUG:

Just before that line, do

Response.Write "DEBUG: strDomain is " & strDomain & "<hr>" & vbNewLine

What does that show you?

And if that isn't line 33, then it would help a lot if you would tell us WHICH line is causing the error.

Old Pedant
08-27-2010, 07:21 PM
This code is utterly bogus:

Dim show
if request.form("btnSubmit") = Show then

All you have done is DIM the Show variable. So its value will be EMPTY.

So when you do the "IF" test you are really saying "If the value from Request.Form("btnSubmit") is empty Then ..."

So it tries to run the code after the THEN *ONLY WHEN THE FORM IS NOT SUBMITTED*!!!

Instead of those two lines, you want *ONE* line that does THIS:

if Trim(request.form("btnSubmit")) = "Show" then

BOBKUSPE
08-27-2010, 08:21 PM
The error message disappeared! However, it is

if Trim(request.form("btnSubmit")) = "Show" then

not works! It will find by an URL called "show". I need a parameter relative to an URL. Based of tyhat it will show the title and body text. The "problem" is to find what is the variable must be used?

NOT WORKS

if Trim(request.form("btnSubmit")) <> " " then

ALSO NOT WORKS

if Trim(request.form("btnSubmit")) = strLink then

Could you fix it to me, please?

Bob

Old Pedant
08-27-2010, 09:41 PM
*EITHER* this line:

if Trim(request.form("btnSubmit")) = "Show" then

or this line:

if Trim(request.form("btnSubmit")) <>"" then

should work.

But NEITHER of those have ANYTHING to do with the HTTP request!

*ONLY* this line matters for that:

strDomain = request.form("strLink")

So DEBUG DEBUG DEBUG!!!!!!

Add in another line:

strDomain = request.form("strLink")
Response.Write "DEBUG: Trying to access URL '" & strDomain & "'<hr>" & vbNewLine


Put that in and show us what the DEBUG shows you!!

BOBKUSPE
08-27-2010, 10:59 PM
You are right! Bad code.

In the screen nothing! Just in the address bar:

http://www.mysite.com/getremotepage.asp?strLink=www.economy.com&btnSubmit=Show

Simply it igones the response.write command
I am trying from my Hosting, not from my HD!

Bob

Old Pedant
08-27-2010, 11:08 PM
First of all, fix your browser!

Click on the TOOLS menu.
Click on INTERNET OPTIONS menu item.
Click on ADVANCED tab.
*UN*check "Show friendly HTTP error message"
OK

Now see if the Response.Write doesn't show up!

It should!

Old Pedant
08-27-2010, 11:13 PM
OH!!! This is too funny!!!!

You are using Request.FORM( ) in your ASP page but your <form> is *NOT* using method="post" so you do NOT HAVE any FORM values!!!!

SORRY! I should have seen that before!

Two choices:
(1) Change Request.Form to simply Request so that it picks up *either* Request.Form or Request.QueryString.
(2) Change
<form method=GET action="">
to
<form method="post" action="">

Or do both.

****************

The other problem you have: Your strDomain is "www.economy.com" but for it to work with ServerXMLHTTP, you *MUST* use a FULL url of "http://www.economy.com".

Either be sure to type "http://" into the form field *OR* add it in your code:

strDomain = "http://" & Trim(Request("strLink"))

BOBKUSPE
08-28-2010, 01:54 AM
I did.

Now it shown an error message:

Microsoft VBScript runtime error '800a0006'

Overflow: 'CInt'

Regarding this:

if CInt(instr(lcase(strHTML),"</title>")) = 0 or CInt(instr(lcase(strHTML),"<title>")+7) = 7 then
strTitle = "No Title"
else
strTitle = Mid(strHTML,CInt(instr(lcase(strHTML),"<title>")+7),strTitleLength)
end if


Or my conexion is slowly or there is a problem in the Web Conexion I changed the Server.ScriptTimeout to 200


BOB

Old Pedant
08-28-2010, 02:10 AM
Well, that means you *ARE* getting something.

But what?

First of all, there is NO REASON AT ALL to use CINT( INSTR( ... ) ). INSTR() is *GUARANTEED* to return an integer! It's POINTLESS to then do CINT() of it.

The problem *appears* to be that your are getting a value for INSTR() that is LARGER than 32767. And CINT() will *ONLY* handle numbers from -32768 to +32767. If you need a larger range, use CLNG( ). But I say again: There is NO REASON to use CINT(INSTR()) so get rid of all those CINT's and see what you get.