• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Data from html table to excel
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Data from html table to excel


  • Subject: Re: Data from html table to excel
  • From: dev_sleidy <email@hidden>
  • Date: Tue, 22 Aug 2006 18:47:04 -0400

I would like to create a applescript that would goto a website containing the current stats for my fantasy baseball league and copy those to a previously existing excel file.

set tURL to "http://baseball.fantasysports.yahoo.com/b1/344356/standings";

set search_String01 to "<td class=\"team\"><a href=\"/b1/344356/"
set search_String02 to "</tr></tbody></table>"
set search_String03 to ">"
set search_String04 to "</a></td>"
set search_String05 to "<td  class=\"stat\">"
set search_String06 to ("</td>" & return)
set search_String07 to "</tr"

set tText to do shell script "curl " & tURL
set tList to {}

repeat 12 times -- Cycle through the twelve (12) teams.

set offset01 to offset of search_String01 in tText -- Start offset point.
set offset02 to ((offset of search_String02 in tText) - 1) -- End offset point.


-- Obtain a sub-set of the web page's source text.
set tText to get (characters (offset01 + (count search_String01)) through offset02 in tText) as string
set offset01 to (offset of search_String03 in tText) -- Start offset point.
set offset02 to ((offset of search_String04 in tText) - 1) -- End offset point.


-- Copy teams title to tList.
copy (get (characters (offset01 + (count search_String03)) through offset02 in tText) as string) to end of tList


-- Obtain a sub-set of tText.
set tText to get (characters (offset02 + (count search_String04)) through (count tText) in tText) as string


 repeat 10 times -- Cycle through the scores of the individual team.

set offset01 to offset of search_String05 in tText -- Start offset point.
set offset02 to ((offset of search_String06 in tText) - 1) -- End offset point.


-- Copy an individual statistic to tList.
copy (get (characters (offset01 + (count search_String05)) through offset02 in tText) as string) to end of tList


--- Obtain a sub-set of tText.
set tText to get (characters (offset02 + (count search_String06)) through (count tText) in tText) as string


 end repeat

 beep

end repeat

tell application "Microsoft Excel"
 activate

if (not (document 1 exists)) then make new document -- Create a new document, if needed.

 -- Make enter titles, etc.
 set (value of cell 4 of row 3) to "Rating"
 set (value of cell 9 of row 3) to "Pitching"

-- Enter statistics headings.
set column_titles to {"R", "HR", "RBI", "SB", "AVG", "W", "SV", "K", "ERA", "WIP"}


 repeat with i from 1 to (count column_titles)
  set (value of cell (i + 1) of row 4) to (item i of column_titles)
 end repeat

 -- Dump the obtained team title and related statistics.
 repeat with i from 1 to ((count column_titles) + 1)
  set (value of cell i of row 5) to (item i of tList)
  set (value of cell i of row 6) to (item (i + 11) of tList)
  set (value of cell i of row 7) to (item (i + 22) of tList)
  set (value of cell i of row 8) to (item (i + 33) of tList)
  set (value of cell i of row 9) to (item (i + 44) of tList)
  set (value of cell i of row 10) to (item (i + 55) of tList)
  set (value of cell i of row 11) to (item (i + 66) of tList)
  set (value of cell i of row 12) to (item (i + 77) of tList)
  set (value of cell i of row 13) to (item (i + 88) of tList)
  set (value of cell i of row 14) to (item (i + 99) of tList)
  set (value of cell i of row 15) to (item (i + 110) of tList)
  set (value of cell i of row 16) to (item (i + 121) of tList)
 end repeat
end tell

---

Also, ...

 -- Dump the obtained team title and related statistics.
 repeat with i from 1 to ((count column_titles) + 1)
...
end repeat

... could be replaced by ...

 -- Dump the obtained team title and related statistics.
 set x to 0
 repeat with i from 5 to 16
  repeat with j from 1 to ((count column_titles) + 1)
   set (value of cell j of row i) to (item (j + x) of tList)
  end repeat
  set x to x + 11
 end repeat
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Data from html table to excel (From: Chris <email@hidden>)

  • Prev by Date: Post to Exchange Public Folder Using Entourage 2004
  • Next by Date: Re: Scripting Adding computers to a list in ARD
  • Previous by thread: Re: Data from html table to excel
  • Next by thread: Re: Data from html table to excel
  • Index(es):
    • Date
    • Thread