![]() I used value=TRUE, so I wouldn't have to worry about the indexing when I restricted myself to the lines from 550 on. > datalines = grep(mypattern,thepage,value=TRUE) Let's grab all the lines that have that pattern: If we look at the lines following this marker, we'll notice that the first date on the schedule can be found in line 536, with the other information following after:īased on the previous step, the data that we want is always preceded by the HTML tag " ". We can locate this line using the grep function: If you look at the web page, you'll see that the title "Opponent / Event" is right above the data we want. Now we have to focus in on what we're trying to extract. You could also save a copy of the result of using readLines, and practice on that until you've got everything working correctly. To make a copy from inside of R, look at the download.file function. Note: When you're reading a web page, make a local copy for testing as a courtesy to the owner of the web site whose pages you're using, don't overload their server by constantly rereading the page. This is actually a good thing, since it usually indicates that the page was generated by a program, which generally makes it easier to extract information from it. The warning messages simply means that the last line of the web page didn't contain a newline character. ![]() Read the contents of the page into a vector of character strings with the readLines function: ![]() Originally for Statistics 133, by Phil SpectorĪs an example of how to extract information from a web page, consider the task of extracting the spring baseball schedule for the Cal Bears from. Berkeley Statistics Annual Research Symposium (BSTARS).Artificial Intelligence/Machine Learning.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |