Attempting to extract the daily forecast from FiveThirtyEight using the rvest
package has proven to be challenging. The object of interest appears to be a javascript object, making it difficult to locate and determine what to look for. Despite limited expertise in CSS and Javascript, efforts have been made to educate on these topics in recent days.
Upon inspecting the webpage element and CSS selector, the following details have been identified:
The target location is
, leading to attempts such as:<div id="polling-avg-chart">
library(rvest) url <- "https://projects.fivethirtyeight.com/election-2016/national-primary-polls/democratic/" url %>% read_html() %> html_nodes("#polling-avg-chart")
However, results have been unsatisfactory with output simply showing:
{xml_nodeset (1)}
[1] <\div id="polling-avg-chart"></div>\n
The individual poll results displayed as dots are located within
, with numerous positions listed numerically. It is apparent that translating<g style="clip-path: url("#line-clippoll_avg");"> ... </g>
cx
andcy
into appropriate percentages will involve utilizing elements like
.<g class="flag-box" transform="translate(30, 161.44093322753096)">...</g>
Unfortunately, the data underlying the forecast line and dots remains elusive.
- Hovering over the chart reveals changes in entities such as
and values like<line class="hover-date-line hide-line">
. These variations may contribute to generating the daily forecast line, yet discovering where this information is stored and linking it to data like "49.1% Clinton vs. 26.6% Sanders" remains enigmatic.<path class="link" d="M 0 171.40106812500002 C 15 171.40106812500002 15 170.94093803735575 30 170.94093803735575"></path>
- Despite exploring other resources like this, none seem tailored to address this specific challenge. How can the forecast percentages be efficiently extracted and organized into a structured dataframe?