2011-09-25 10 views
0

Automator 워크 플로에서 URL 목록을 "Run AppleScript"로 전달하고 각 페이지의 내용을 가져 와서 연결하고 BBedit (또는 다른 텍스트 편집기).AppleScript cURL 및 구문 분석 URL

on run {input, parameters} 

    tell application "BBEdit" 
     activate 

     set astid to AppleScript's text item delimiters 

     set startHere to "<tbody>" 
     set stopHere to "</tbody>" 

     repeat with anItem in input 

      set blurb0 to (do shell script "curl " & anItem) 
      set AppleScript's text item delimiters to startHere 
      set blurb1 to text item 2 of blurb0 
      set AppleScript's text item delimiters to stopHere 
      set blurb2 to text item 1 of blurb1 

      set AppleScript's text item delimiters to astid 

      return blurb2 
      beep 

     end repeat  

    end tell 

end run 

현재 코드는 첫 번째 URL의 내용 만 올바르게 수신합니다. 아무도이 문제를 해결할 수 있습니까?

답변

0

이 서브 루틴은

on getSource(this_URL) 
    tell application "Safari" 
     activate 
     set the URL of the current tab of document 1 to this_URL 
     set the |source| to the source of the front document 
    end tell 
    tell application "TextEdit" 
     activate 
     set the text of the front document to the source 
    end tell 
    quit application "Safari" 
end getSource 

사용하여 전화 ... 당신이 (당신이 사파리를 사용하는 경우) 필요한 수 있습니다 :

repeat with anItem in input 
    getSource(input) 
end repeat 

난이 도움이되기를 바랍니다!

0

repeat with anItem in input 루프 안에 있기 때문에 첫 번째 항목에 대한 모든 작업을 수행하고 return은 루프를 종료하고 실제로 Automator 작업 전체를 종료합니다. 나는 당신이 스크립트에서 beep을 들어 본 적이없는 것 같아요 ;-)

다른 측면에서 저는 BBEdit가 당신을 위해 cUrl과 정렬 작업을하는 이유가 궁금합니다. ,

on run {input, parameters} 

    -- define a few parameters 
    set astid to AppleScript's text item delimiters 
    set startHere to "<tbody>" 
    set stopHere to "</tbody>" 

    -- define a list to store all found content 
    set allFoundContent to {} 

    repeat with anItem in input 

     set blurb0 to (do shell script "curl " & anItem) 
     set AppleScript's text item delimiters to startHere 
     set blurb1 to text item 2 of blurb0 
     set AppleScript's text item delimiters to stopHere 

     -- put the found content at the end of the list 
     set end of allFoundContent to text item 1 of blurb1 

     set AppleScript's text item delimiters to astid 

    end repeat 

    -- from here you have three possibilities: 
    -- 1. return the list to next Automator action (uncomment the next line): 

    -- return allFoundContent 


    -- 2. concatenate the list with a delimiter you like (here return & "------" & return) 
    -- and give it to your preferred text editor from this point (uncomment the next lines): 

    -- set AppleScript's text item delimiters to return & "------" & return 
    -- tell application "TextEdit" 
    --  make new document with properties {text: allFoundContent as text} 
    -- end tell 
    -- set AppleScript's text item delimiters to astid 


    -- 3. concatenate the list with a delimiter you like (here return & "------" & return) 
    -- and give it to the next workflow step, maybe a BBEdit action waiting for a string? (uncomment the next lines): 

    -- set AppleScript's text item delimiters to return & "------" & return 
    -- set returnString to allFoundContent as text 
    -- set AppleScript's text item delimiters to astid 
    -- return returnString 


    -- Next decision (for choice 1 or 2): 
    -- What do you want to give to next Automator action? 

    -- you can pass your input (the given URLs) (uncomment next line): 
    -- return input 

    -- or your result list (uncomment next line): 
    -- return allFoundContent 
end run 

인사말 마이클/함부르크

을 모든라는 핸들러

내가 당신의 핸들러가 다음과 같이해야한다고 생각 ...는 BBEdit에 속하지 않는