Help to Modify this code so it works for this website

bsharath
bsharath used Ask the Experts™
on
help to
Modify this code so it works for this website

http://mtas.surfcontrol.com/mtas/MTAS.asp

retrieve the category to a column

I will have the website names into the txt file

Script scans each site with "mtas.surfcontrol.com" and lists the category


strInputFile = "input.txt"
strOutputFile = "output.txt"

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objHTTP = CreateObject("MSXML2.XMLHTTP")

Set objInput = objFSO.OpenTextFile(strInputFile, 1, False)
Set objOutput = objFSO.CreateTextFile(strOutputFile, True)

Set objIE = CreateObject("InternetExplorer.Application")
objIE.Visible = True
objIE.Navigate "http://moonsy.com/pagerank_checker/"
While objIE.busy = True Or objIE.ReadyState <> 4
      WScript.Sleep 100
Wend

While Not objInput.AtEndOfStream
      strURL = Trim(objInput.ReadLine)
      If strURL <> "" Then
            objIE.document.form1.domain.value = strURL
            objIE.document.form1.submit.click
            While objIE.busy = True Or objIE.ReadyState <> 4
                  WScript.Sleep 100
            Wend
            strRank = InStr(1, objIE.Document.body.innerText, "your page rank", vbTextCompare)
            If strRank = 0 Then
                  objOutput.WriteLine strURL & ",NOT FOUND"
                  'WScript.Echo strURL & ",NOT FOUND"
            Else
                  strRank = Replace(Trim(Mid(objIE.Document.body.innerText, strRank, 21)), "Your Page Rank:", "")
                  objOutput.WriteLine strURL & "," & strRank
                  'WScript.Echo strURL & "," & strRank
            End If
      End If
Wend
objInput.Close
objOutput.Close

Set objHTTP = Nothing
objIE.Quit
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Author

Commented:
Some more info
The current code above places each website name in a site http://moonsy.com/pagerank_checker/ and finds the PR

Now the same code can we change to be placed from txt file each website name into
http://mtas.surfcontrol.com/mtas/MTAS.asp

then find what category the website is from?
Software Engineer
Commented:
How about this:
Const strInputFile = "input.txt"
Const strOutputFile = "output.txt"

Const C_URL = "http://mtas.surfcontrol.com/mtas/MTAS.asp"
Const C_TXT = " is in our list and categorized as "

Set objFSO = CreateObject("Scripting.FileSystemObject")
'Set objHTTP = CreateObject("MSXML2.XMLHTTP")

Set objInput = objFSO.OpenTextFile(strInputFile, 1, False)
Set objOutput = objFSO.CreateTextFile(strOutputFile, True)

Set objIE = CreateObject("InternetExplorer.Application")
objIE.Visible = True
While Not objInput.AtEndOfStream
      ' do this now _inside_ the loop because result page does not contain the input form
      objIE.Navigate C_URL
      While objIE.busy = True Or objIE.ReadyState <> 4
            WScript.Sleep 100
      Wend

      strURL = Trim(objInput.ReadLine)
      If strURL <> "" Then
            objIE.Document.form1.URL.Value = strURL
            objIE.Document.form1.submit
            While objIE.busy = True Or objIE.ReadyState <> 4
                  WScript.Sleep 100
            Wend
            ' find category text; note: first integer, then string
            strCategory = InStr(1, objIE.Document.body.innerText, C_TXT, vbTextCompare)
            If strCategory = 0 Then
                  objOutput.WriteLine strURL & ",NOT FOUND"
                  'WScript.Echo strURL & ",NOT FOUND"
            Else
                  strCategory = Mid(objIE.Document.body.innerText, strCategory + Len(C_TXT))
                  strCategory = Left(strCategory, InStr(strCategory, vbCrLf) - 1)
                  'following line is not necessary because property .innerText already strips out HTML
                  'strcategory = Replace(strcategory, "<font color=#CC0000><b>", "")
                  strCategory = Trim(strCategory)
                  objOutput.WriteLine strURL & "," & strCategory
                  'WScript.Echo strURL & "," & strCategory
            End If
      End If
Wend
objInput.Close
objOutput.Close

'Set objHTTP = Nothing
objIE.Quit

Open in new window

Author

Commented:
Thanks a lot
Works like a charm

Can you help with this
http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/Excel/Q_27978528.html

Similar to the first one
Success in ‘20 With a Profitable Pricing Strategy

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Robert SchuttSoftware Engineer

Commented:
I had a quick look but it seems there will be a different screen when you are logged in as administrator (multiple edit buttons?). Maybe you should post some more info like a screendump of how it looks for you and clearly marked which part (or multiple parts) you want to change (and which steps that will entail). I didn't post in that new question because it might put other experts off if you're already receiving help (I have a saved search myself that looks explicitly for questions that have nobody helping yet).

It would probably help attracting other experts if you post a link to earlier solutions (like http:/Q_27976953.html). Also, often it's better to show that you made an effort at solving at least part of it and only then ask for specific help with some adjustments that you can't work out yourself.

HTH, Robert.

Author

Commented:
Thanks Robert

When you login to the post i mentioned with the credentials you can see an Edit button and i will have the same in my admin screen as well but a few others like delete comment etc may be available

I have added the screenshot in that post , please have a look
Robert SchuttSoftware Engineer

Commented:
I'll leave that new question open for now, I'm afraid I don't have the time to try and tackle it today/tonight. At first glance it seems like a horrible task to parse that output, if it's capturable at all. Have you tried looking for code to detect/follow http redirects directly instead of via that website?

Author

Commented:
>.Have you tried looking for code to detect/follow http redirects directly instead of via that website?

No can you please direct me so i can search
Robert SchuttSoftware Engineer

Commented:
A quick google shows that it should be possible to use the HTTP request for a HEAD operation instead of the default GET. Then you can determine the new url. If necessary repeat (not sure about that though). I'll have to try it out and if I find something will post on your new question.
Robert SchuttSoftware Engineer

Commented:
bit busy at the moment but check this out, second script on this page: http://www.paulsadowski.com/wsh/xmlhttp.htm
Robert SchuttSoftware Engineer

Commented:
I was wrong about parsing the output of that website, will post a solution on your follow-up question shortly.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial