We need a script in python that can extract state by state polling information concerning specifically to the presidential general election between Trump vs. Clinton and collate it into one CSV file.
Polling Information for presidential general election between Trump vs. Clinton can be found at:
Note that state by state information can be found with standardized url:
For example polling information for Trump vs Clinton in North Carolina:
And polling information for Trump vs Clinton in Iowa:
Also note that data can be extracted in CSV by adding ".csv" at the end of each URL. For example:
However there are cases where the url does not follow the same format. For example:
Following these specifications, the Script should:
-Look into each state, regardless of url difference
-Obtain state by state polling information for presidential general election between Trump vs. Clinton in CSV file
-Collect all information and collate it into one CSV file.
The final collated CSV should:
Follow the same format and look exactly like polls_2012.csv attached here.
-Day = number of day in the year, e.g. 1/2/2016 = 2,
-Len=length of poll, e.g. 1/2/2016 to 1/5/2016 = 3,
-State=name of the state, e.g. Alabama
-EV=number of electoral votes in each state, e.g. Alaska = 3, this column should be the same for 2012 and 2016.
-Dem= In this case, votes for Clinton
-GOP= Votes for Trump
-Ind= column left blank
-Date = Entry Date
-Required seven columns between Date and Pollster
-Pollster = Name of pollster, e.g. Rasmussen-1