2016-07-14 1 views
0

AppleScript를 사용하여 웹 사이트에서 정보를 얻으려고하고 있는데 "예상 줄 끝 등이 있지만 식별자를 발견했습니다." 자바 스크립트getInfoByClass의 간단한 오류입니까?

강조 오류가 Heres는 잘못된 코드의 섹션

to getInputByClass(theClass, num) 

    tell application "Google Chrome" 

     set input to do JavaScript "document.getElementsByClassName('" & theClass & "')[" & num & "].innerHTML;" in document 1 

    end tell 

    return input 

end getInputByClass 

나는 또한 도움을

tell application "Google Chrome" 
    activate 
    set theScript to "document.getElementsByClassName('" & theClass & "')[" & num & "].innerHTML;" 
    do JavaScript theScript in current tab of first window 
end tell 

감사를 사용하여 시도 및 실패!

답변

0

스크립팅 사전을 살펴보십시오. Google 크롬에 대해 정의 된 do javascript -handler가 없습니다. 대신 execute를 찾을 수 :

to getInputByClass(theClass, num) 

    tell application "Google Chrome" 
     tell active tab of window 1 
      set input to execute javascript "document.getElementsByClassName('" & theClass & "')[" & num & "].innerHTML;" 
     end tell 
    end tell 

    return input 

end getInputByClass 

당신이

getInputByClass("current-site-link site-link js-gps-track", 0) 

으로이 쪽이 핸들러를 호출 할 경우 결과로

<div class=\"site-icon favicon favicon-stackoverflow\" title=\"Stack Overflow\"></div> 
      Stack Overflow 

받아야합니다. 아래와 같이

재밌게 마이클/함부르크

1

내 전체 코드 (아주 짧은)는 지금이다. 자바 스크립트에서 b 열로 이동하는 정보를 게시하는 코드를 가져올 수 없습니다. 그 문제를 해결하기 위해 당신은 무엇을 할 것입니까? 다시 한번 감사드립니다.

세트 I를 1

725 회 반복

activate application "Microsoft Excel" 

tell application "Microsoft Excel" 
    select cell ("a" & (i as string)) 
end tell 

tell application "System Events" 
    keystroke "c" using command down 
    delay 1 
end tell 

activate application "Google Chrome" 

tell application "System Events" 
    keystroke "t" using command down 
    delay 1 
    keystroke "https://bookscouter.com/prices.php?isbn=" 
    keystroke "v" using command down 
    keystroke "&searchbutton=Sell" 
    delay 1 
    keystroke return 
    delay 10 
end tell 

set theText to getInputByClass("book-prices", 0) 
tell application "Microsoft Excel" 
    set value of cell ("b" & (i as string)) to theText 
end tell 

set i to i + 1 

tell application "System Events" 
    keystroke "w" using command down 
end tell 

최종 반복

getInputByClass (하는 theClass, NUM)

tell application "Google Chrome" 
    tell active tab of window 1 
     set input to execute javascript "document.getElementsByClassName('" & theClass & "')[" & num & "].innerHTML;" 
    end tell 
end tell 

return input 

단부 getInputByClass