Applescript if url of tab contains "text" click link


 
Thread Tools Search this Thread
Top Forums Programming Open Source Applescript if url of tab contains "text" click link
# 1  
Old 03-26-2015
Code Applescript if url of tab contains "text" click link

this works for what i need it to, but need to add function that will click on link if urloftab contains "300"

the last url of each page ends in "300", so i figure that if I add a function that for every tab it open it will also search to see if url contains "300". if it contains "300" click link to next page.

this right now works , it opens a list of URL's and searches each one for "text", the site im searching only allows for 300 records to be shown at one time, i have to search hundreds of thousands of records. and I would rather not have to manually click the next button every time it reaches the last URL in the list.
and it searches 300 records in about 11 minutes, and i would rather not wait every 11 minutes to click to continue.

i would need it to, while it has tab open and efter it has searched the page itself and saved the URL in the text file, then also search the URL of the tab for "300", if it contains "300" then close tab and click the next link in the current safari page

Code:
on run {input, parameters}
	read (item 1 of input)
	set ps to paragraphs of the result
	set tot to count ps
	tell application "Safari"
		reopen
		activate
	end tell
	repeat with i from 1 to tot
		set p to item i of ps
		if p is not "" then
			try
				tell application "Safari"
					tell front window
						set r to make new tab with properties {URL:p}
						set current tab to r
						delay 1
						if i = tot then exit repeat
						repeat
							delay 1
							
							tell application "Safari"
								activate
								
								--the source code of current Tab
								set sourceOfTab to source of front document
								
								set urlOfTab to URL of front document
								
								if sourceOfTab contains "1/28/2015" then
									
									--copy of the url in textFile
									do shell script "echo " & urlOfTab & " >> ~/text.txt"
									close current tab of front window
									
								else
									close current tab of front window
								end if
							end tell
							
							
							
							get URL of r
						end repeat
					end tell
				end tell
			end try
		end if
	end repeat
end run


this is what the source of the next button contains on the site im searching, i dont know what class or handle or ID or name that it needs to find the link. every link is a little bit different for each batch of 300 records. the only thing that changes is the ahref

Code:
			

	 </table>


<form action="searchresults.asp" method="Post">
<input type="hidden" name="intpage" value="2">

<table width="100%" border="0" cellspacing="0" cellpadding="2">
	<tr>
	
		<td align="center"></td>
		<td align="right"><a href="searchresults.asp?p=2&amp;qs=a&amp;st=2&amp;lqs=ABERNATHY+MARGUERITE+TR+1%2FNCNB&amp;d=False" onmousedown="document.images['Next'].src='images/arrow_rightdown.gif'"><img src="images/arrow_rightup.gif" name="Next" border="0"></a></td>
		</tr>
	
</table>

            </div>
          </td>
        </tr>
      </table>
	</td>
</tr>
</table>


ive been trying to piece it together with some of these, but i keep getting errors, i dont know programming
Code:
tell document 1

        do JavaScript "document.getElementsByClassName('proceed')[0].click()"

    end tell

Code:
tell application "Safari"
    do JavaScript "document.getElementsByClassName(\"lnkDownloadTransactions.lightbox-launcher\").click();" in window 1
end tell

Code:
tell application "Safari"
    activate
    tell document 1
        do JavaScript "document.getElementById('button-id').click();"
    end tell
end tell

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

2. UNIX for Advanced & Expert Users

How to troubleshoot "Java down" is on my Linux webserver. It caused my web URL to go down.?

On my server java is down which caused my web URL to go down. How could I troubleshoot java related issues on my server (0 Replies)
Discussion started by: vinay2926
0 Replies

3. Shell Programming and Scripting

Applescript to open webpage from list, search for "text"

hi guys, its me, doritos guy, I've laid off of the doritos for a while, twas given me stomach problems. you know when you eat 10 family size bags a day it might cause a problem, any-who i appreciated the help from last time when i was trying to script something, now i just have to try to... (2 Replies)
Discussion started by: ilovedoritos
2 Replies

4. OS X (Apple)

Applescript to open webpages from list, search for "text"

posted this first in the shell area, realized it was wrong area for this, forgive me hi guys, its me, doritos guy, I've laid off of the doritos for a while, twas given me stomach problems. you know when you eat 10 family size bags a day it might cause a problem, any-who i appreciated the help... (0 Replies)
Discussion started by: ilovedoritos
0 Replies

5. AIX

Have to click "enter" key twice to successfully login

Hi Guys, When using plink ( plink -ssh $IP) to connect to an AIX box, the password is correct, but always after input the password and click enter I got "access denied", then I am promted for password again, this time no matter what password I give, correct or bad, after I re-click enter, as... (2 Replies)
Discussion started by: kensview
2 Replies

6. Shell Programming and Scripting

Using sed to find text between a "string " and character ","

Hello everyone Sorry I have to add another sed question. I am searching a log file and need only the first 2 occurances of text which comes after (note the space) "string " and before a ",". I have tried sed -n 's/.*string \(*\),.*/\1/p' filewith some, but limited success. This gives out all... (10 Replies)
Discussion started by: haggismn
10 Replies

7. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

8. Shell Programming and Scripting

read -p "prompt text" foo say "read: bad option(s)" in Bourne-Shell

Hallo, i need a Prompting read in my script: read -p "Enter your command: " command But i always get this Error: -p: is not an identifier When I run these in c-shell i get this error /usr/bin/read: read: bad option(s) How can I use a Prompt in the read command? (9 Replies)
Discussion started by: wiseguy
9 Replies

9. UNIX for Dummies Questions & Answers

Convert "text" to "packed-decimal"?

Is there a way with HP-UX Release 10.20 (but going to HP-UX 11) to convert a regular "text" file to a packed data format (such as is created by a Cobol program)? (2 Replies)
Discussion started by: HuskyJim
2 Replies
Login or Register to Ask a Question