Issue
I am attempting to scrape scheduling data for my squadron from: https://www.cnatra.navy.mil/scheds/schedule_data.aspx?sq=vt-9
I have figured out how to extract the data using BeautifulSoup using:
import urllib2
from urllib2 import urlopen
import bs4 as bs
url = 'https://www.cnatra.navy.mil/scheds/schedule_data.aspx?sq=vt-9'
html = urllib2.urlopen(url).read()
soup = bs.BeautifulSoup(html, 'lxml')
table = soup.find('table')
print(table.text)
However, the table is hidden under the date is selected (if other than the current day) and the 'View Schedule' button is pressed.
How can I modify my code to 'press' the 'View Schedule' button so I can then scrape the data? Bonus points if the code can also choose a date!
I attempted to use:
import urllib2
from urllib2 import urlopen
import bs4 as bs
from selenium import webdriver
driver = webdriver.Chrome("/users/base/Downloads/chromedriver")
driver.get("https://www.cnatra.navy.mil/scheds/schedule_data.aspx?sq=vt-9")
button = driver.find_element_by_id('btnViewSched')
button.click()
which successfully opens Chrome and 'clicks' the button, but I can't scrape from this as the address is unchanged.
Solution
You can use pure selenium
to get the schedule:
from selenium import webdriver
driver = webdriver.Chrome('chromedriver.exe')
driver.get("https://www.cnatra.navy.mil/scheds/schedule_data.aspx?sq=vt-9")
button = driver.find_element_by_id('btnViewSched')
button.click()
print(driver.find_element_by_id('dgEvents').text)
Output:
TYPE VT Brief EDT RTB Instructor Student Event Hrs Remarks Location
Flight VT-9 07:45 09:45 11:15 JARVIS, GRANT M [LT] LENNOX, KEVIN I [ENS] BI4101 1.5 2 HR BRIEF MASS BRIEF
Flight VT-9 07:45 09:45 11:15 MOYNAHAN, WILLIAM P [CDR] FINNERAN, MATTHEW P [1stLt] BI4101 1.5 2 HR BRIEF MASS BRIEF
Flight VT-9 07:45 12:15 13:45 JARVIS, GRANT M [LT] TAYLOR, ADAM R [1stLt] BI4101 1.5 2 HR BRIEF MASS BRIEF @ 0745 W/ JARVIS MEI OPS
Flight VT-9 07:45 12:15 13:45 MOYNAHAN, WILLIAM P [CDR] LOW, TRENTON G [ENS] BI4101 1.5 2 HR BRIEF MASS BRIEF @ 0745 W/ MOYNAHAN MEI OPS
Watch VT-9 00:00 14:00 ANDERSON, LAURA [LT] ODO (ON CALL) 14.0
Watch VT-9 00:00 14:00 ANDERSON, LAURA [LT] ODO (ON CALL) 14.0
Watch VT-9 00:00 23:59 ANDERSON, LAURA [LT] ODO (ON CALL) 24.0
Watch VT-9 00:00 23:59 ANDERSON, LAURA [LT] ODO (ON CALL) 24.0
Watch VT-9 07:00 19:00 STUY, JOHN [LTJG] DAY IWO 12.0
Watch VT-9 19:00 07:00 STRACHAN, ALLYSON [LTJG] IWO 12.0
Answered By - Alderven
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.