Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to Send Line to a URL

Status
Not open for further replies.

processx

Programmer
Feb 10, 2011
3
0
0
US
Hi i have been working on this project for weeks now, i am stuck. Help?????

Ok this is what i want to do, i wanted to write a program that will read a text file which has a list of URLs, i want to be able to read these URLs from the file (which i have already done) and put it in the URL box in Internet Explorer (My problem).

Code:

Dim objFSO, objTextFile, strComputer, i, strText, arrComputers(), indx, arrFileLines()
Dim objShell,objOUT, WsShell, ie

Set objShell = CreateObject("WScript.Shell")

indx = 0
i = 0
Const ForReading = 1

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile _
("C:\Documents and Settings\agiobop.USWIN\Desktop\Scripts\hosp_list-code.txt", ForReading)

Set objoutputFile = objFSO.CreateTextFile("C:\Documents and Settings\agiobop.USWIN\Desktop\Scripts\copycat.txt")

' Placing text lines into an array
Do Until objTextFile.AtEndOfStream
Redim Preserve arrFileLines(i)
arrFileLines(i) = objTextFile.ReadLine
i = i + 1
Loop
'WScript.Echo i ' <<<<<<<<< Used outside 1st loop as condition for 2nd loop

set ie = createobject("internetexplorer.application") ' run internet explorer
ie.visible = true
While ie.busy ' wait for IE to load-up
DoEvents
Wend

ie.navigate "URL" ' navigate to internet explorer
Do Until indx = i

'WScript.Echo arrFileLines(indx-1)
'ArrCheck = len(arrFileLines(indx-1)) ' <<<<<<<<< veryfies that we actually have the text assigned to arrays

'THIS IS WHERE I WANT TO SEND THE STRINGS IN MY ARRAY TO THE URL
objShell.SendKeys arrFileLines(indx)
objShell.SendKeys "{ENTER}" 'Execute URL

ie.visible = true
While ie.busy ' wait for IE to load-up
Wscript.Sleep 5000
Wend
objShell.SendKeys "%"
Wscript.sleep 100
objShell.SendKeys "+{F10}"
Wscript.sleep 100
objShell.SendKeys "{DOWN}"
Wscript.sleep 100
objShell.SendKeys "{DOWN}"
Wscript.sleep 100
objShell.SendKeys "{DOWN}"
Wscript.sleep 100
objShell.SendKeys "{DOWN}"
Wscript.sleep 100
objShell.SendKeys "{DOWN}"
Wscript.sleep 100
objShell.SendKeys "{DOWN}"
Wscript.sleep 100
objShell.SendKeys "{DOWN}"
Wscript.sleep 100
objShell.SendKeys "{DOWN}"
Wscript.sleep 100
objShell.SendKeys "{DOWN}"
Wscript.sleep 100
objShell.SendKeys "{DOWN}"
Wscript.sleep 400
objShell.SendKeys "{ENTER}"
WScript.Sleep 2000
objShell.SendKeys "^A" ' Highlight
Wscript.sleep 1000
objShell.SendKeys "^C" ' Copy
Wscript.sleep 1000
objShell.SendKeys "%{F4}"
Wscript.sleep 400

indx = indx + 1
Loop
'WScript.Echo indx ' <<<<<<<<< Verify the number of loop iterations
'WScript.Echo ArrCheck <<<<<<<<<<

objTextFile.Close
WScript.Quit
 
In practically no case you use sendkeys unless you lost control to everything. You should look into the source code of "URL" page under the ie object once loaded and proceed to put data to the appropriate controls inside the page.
 
@ tsuji, could you please give an example of how i am supposed to go about looking into the source code and even how to put a link in the URL in the source code and load it, i will appreciate it gr8ly...
 
What is this ?
ie.navigate "URL"

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
@PHV ie.navigate sends the cursor to the URL box, just like clicking on it the manually enter a website
 
Why not this ?
ie.navigate arrFileLines(indx)

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
[0]
Q:>how i am supposed to go about looking into the source code
A: Every browser has some button so that user can look at the source code. But if you have no idea of html, then it falls into the category of "lost control to everything."

[1]
Q:>and even how to put a link in the URL in the source code and load it...
A: below...

[1.1] Let's say and url is given (surl below) from whatever source (readline or whatever...) and the page has this simple layout for illustration.
[tt]
<!-- this page [ignore][/ignore] -->
<html>
<body>
<form name="formname">
<input type="text" name="txtbox" /><br />
<input type="password" name="pwd" /><br />
</form>
</body>
</html>
[/tt]
[1.2] The loading and send data to the text boxes looks like this.
[tt]
[green]surl="[ignore][/ignore]"[/green] 'given from somewhere

set oie=createobject("internetexplorer.application")
with oie
.navigate "about:blank"
do while oie.readystate<>4 : wscript.sleep 50 : loop
.visible=true
.navigate surl
do while oie.readystate<>4 : wscript.sleep 50 : loop
end with

set oform=oie.document.formname
with oform
.txtbox.value="somename"
.pwd.value="somepassword"
end with

'oform.submit 'submit the form (based on the simplest construction only)
[/tt]
[2.2] If you have no idea of any of the above and cannot read the script visually line-by-line and get the essence of it, then you have to start with the basic rather than jump immediately into a territory where quite of bit of different technologies tend to together to make thing work. That is not an efficient way to do thing.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top