Solved

Help to Modify this code so it works for this website

Posted on 2012-12-20
11
329 Views
Last Modified: 2013-06-17
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
0
Comment
Question by:bsharath
  • 6
  • 5
11 Comments
 
LVL 11

Author Comment

by:bsharath
ID: 38723147
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?
0
 
LVL 35

Accepted Solution

by:
Robert Schutt earned 500 total points
ID: 38723312
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

0
 
LVL 11

Author Comment

by:bsharath
ID: 38723367
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
0
 
LVL 35

Expert Comment

by:Robert Schutt
ID: 38723563
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.
0
 
LVL 11

Author Comment

by:bsharath
ID: 38724210
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
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 11

Author Comment

by:bsharath
ID: 39237376
0
 
LVL 35

Expert Comment

by:Robert Schutt
ID: 39238091
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?
0
 
LVL 11

Author Comment

by:bsharath
ID: 39238099
>.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
0
 
LVL 35

Expert Comment

by:Robert Schutt
ID: 39244490
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.
0
 
LVL 35

Expert Comment

by:Robert Schutt
ID: 39244506
bit busy at the moment but check this out, second script on this page: http://www.paulsadowski.com/wsh/xmlhttp.htm
0
 
LVL 35

Expert Comment

by:Robert Schutt
ID: 39252484
I was wrong about parsing the output of that website, will post a solution on your follow-up question shortly.
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
A short article about problems I had with the new location API and permissions in Marshmallow
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now