Do you want "LTD- " by the date?
Added:
column headers
split change and %change
error checking to stop if output is locked by Excel
tray tip to so progress of the data pull
Code:
Opt("TrayIconDebug", 1)
$S_running = "~stock-stuff~" ;name the script
If WinExists($S_running) Then Exit
AutoItWinSetTitle($S_running)
#include<Inet.au3>
#include <String.au3>
$whole_file = FileRead("symbol.txt")
$account_number_array = StringSplit($whole_file, @CRLF, 1)
$file_h = FileOpen("output.csv", 2)
If $file_h = -1 Then
MsgBox(0, "AutoIt", "Could not open output file. Close Excel?")
Exit
EndIf
FileWriteLine($file_h, _
"Code" & "," & _
"Name" & "," & _
"Date" & "," & _
"Change" & "," & _
"% Change" & "," & _
"Close" & "," & _
"High" & "," & _
"Low" & "," & _
"Wtd. Avg Price" & "," & _
"TTQ")
For $i = 1 To $account_number_array[0]
TrayTip("Pulling stock data ", "Stock " & $i & " of " & $account_number_array[0], 100)
If $account_number_array[$i] = "" Then ContinueLoop ;skip empty lines
$page_source = _INetGetSource("http://m.bseindia.com/StockReach.aspx?scripcd=" & $account_number_array[$i], 1)
$spanCname = _StringBetween($page_source, '<span id="spanCname" class="companyname">', '</span><br>')
If @error Then _errors($account_number_array[$i])
$strongDate = _StringBetween($page_source, '<span id="strongDate">', '</span>')
If @error Then _errors($account_number_array[$i])
$spanchangVal = _StringBetween($page_source, '<span id="spanchangVal" class="srcovalue">', '</span>')
If @error Then _errors($account_number_array[$i])
If StringInStr($spanchangVal[0], "(") Then
$spanchangVal_array = StringSplit($spanchangVal[0], "(", 1)
$spanchangVal_array[1] = StringStripWS($spanchangVal_array[1], 8)
$spanchangVal_array[2] = StringReplace($spanchangVal_array[2], ")", "")
$spanchangVal_array[2] = StringStripWS($spanchangVal_array[2], 8)
Else
Global $spanchangVal_array[3]
$spanchangVal_array[1] = "null"
$spanchangVal_array[2] = "null"
EndIf
$strongCvalue = _StringBetween($page_source, '<span class="srcovalue"><strong id="strongCvalue">', '</strong></span>')
If @error Then _errors($account_number_array[$i])
$tdDHL = _StringBetween($page_source, '<td id="tdDHL" class="TTRow_right">', '</td>')
If @error Then _errors($account_number_array[$i])
If StringInStr($tdDHL[0], "/") Then
$tdDHL_array = StringSplit($tdDHL[0], "/", 1)
Else
Global $tdDHL_array[3]
$tdDHL_array[1] = "null"
$tdDHL_array[2] = "null"
EndIf
$tdWAp = _StringBetween($page_source, '<td id="tdWAp" class="TTRow_right">', '</td>')
If @error Then _errors($account_number_array[$i])
$tdTTQW = _StringBetween($page_source, '<td id="tdTTQW" class="TTRow_right">', '</td>')
If @error Then _errors($account_number_array[$i])
FileWriteLine($file_h, _
$account_number_array[$i] & "," & _
$spanCname[0] & "," & _
$strongDate[0] & "," & _
$spanchangVal_array[1] & "," & _
$spanchangVal_array[2] & "," & _
$strongCvalue[0] & "," & _
$tdDHL_array[1] & "," & _
$tdDHL_array[2] & "," & _
$tdWAp[0] & "," & _
$tdTTQW[0])
Next
FileClose($file_h)
MsgBox(0, "AutoIt", "Finished!")
Func _errors($pass)
MsgBox(0, "AutoIt", "Error - not a valid stock number: " & $pass)
ShellExecute("http://m.bseindia.com/StockReach.aspx?scripcd=" & $pass)
FileClose($file_h)
Exit
EndFunc
edit:
Same as above - only without "LTD- " by the date:
Code:
Opt("TrayIconDebug", 1)
$S_running = "~stock-stuff~" ;name the script
If WinExists($S_running) Then Exit
AutoItWinSetTitle($S_running)
#include<Inet.au3>
#include <String.au3>
$whole_file = FileRead("symbol.txt")
$account_number_array = StringSplit($whole_file, @CRLF, 1)
$file_h = FileOpen("output.csv", 2)
If $file_h = -1 Then
MsgBox(0, "AutoIt", "Could not open output file. Close Excel?")
Exit
EndIf
FileWriteLine($file_h, _
"Code" & "," & _
"Name" & "," & _
"Date" & "," & _
"Change" & "," & _
"% Change" & "," & _
"Close" & "," & _
"High" & "," & _
"Low" & "," & _
"Wtd. Avg Price" & "," & _
"TTQ")
For $i = 1 To $account_number_array[0]
TrayTip("Pulling stock data ", "Stock " & $i & " of " & $account_number_array[0], 100)
If $account_number_array[$i] = "" Then ContinueLoop ;skip empty lines
$page_source = _INetGetSource("http://m.bseindia.com/StockReach.aspx?scripcd=" & $account_number_array[$i], 1)
$spanCname = _StringBetween($page_source, '<span id="spanCname" class="companyname">', '</span><br>')
If @error Then _errors($account_number_array[$i])
$strongDate = _StringBetween($page_source, '<span id="strongDate">LTD- ', '</span>')
If @error Then _errors($account_number_array[$i])
$spanchangVal = _StringBetween($page_source, '<span id="spanchangVal" class="srcovalue">', '</span>')
If @error Then _errors($account_number_array[$i])
If StringInStr($spanchangVal[0], "(") Then
$spanchangVal_array = StringSplit($spanchangVal[0], "(", 1)
$spanchangVal_array[1] = StringStripWS($spanchangVal_array[1], 8)
$spanchangVal_array[2] = StringReplace($spanchangVal_array[2], ")", "")
$spanchangVal_array[2] = StringStripWS($spanchangVal_array[2], 8)
Else
Global $spanchangVal_array[3]
$spanchangVal_array[1] = "null"
$spanchangVal_array[2] = "null"
EndIf
$strongCvalue = _StringBetween($page_source, '<span class="srcovalue"><strong id="strongCvalue">', '</strong></span>')
If @error Then _errors($account_number_array[$i])
$tdDHL = _StringBetween($page_source, '<td id="tdDHL" class="TTRow_right">', '</td>')
If @error Then _errors($account_number_array[$i])
If StringInStr($tdDHL[0], "/") Then
$tdDHL_array = StringSplit($tdDHL[0], "/", 1)
Else
Global $tdDHL_array[3]
$tdDHL_array[1] = "null"
$tdDHL_array[2] = "null"
EndIf
$tdWAp = _StringBetween($page_source, '<td id="tdWAp" class="TTRow_right">', '</td>')
If @error Then _errors($account_number_array[$i])
$tdTTQW = _StringBetween($page_source, '<td id="tdTTQW" class="TTRow_right">', '</td>')
If @error Then _errors($account_number_array[$i])
FileWriteLine($file_h, _
$account_number_array[$i] & "," & _
$spanCname[0] & "," & _
$strongDate[0] & "," & _
$spanchangVal_array[1] & "," & _
$spanchangVal_array[2] & "," & _
$strongCvalue[0] & "," & _
$tdDHL_array[1] & "," & _
$tdDHL_array[2] & "," & _
$tdWAp[0] & "," & _
$tdTTQW[0])
Next
FileClose($file_h)
MsgBox(0, "AutoIt", "Finished!")
Func _errors($pass)
MsgBox(0, "AutoIt", "Error - not a valid stock number: " & $pass)
ShellExecute("http://m.bseindia.com/StockReach.aspx?scripcd=" & $pass)
FileClose($file_h)
Exit
EndFunc
edit2:
added some error checking as some webpages caused the script to error out.