Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I scrape bank of america for business hours?

Hi I was wondering how I can use beautifulsoup to scrape bank of america for its hours. For example, if the url is (Shattuck_Ave_94704_BERKELEY_CA/bank_branch_locations/">http://locators.bankofamerica.com/locator/locator/2129_Shattuck_Ave_94704_BERKELEY_CA/bank_branch_locations/) how can i extract hours only? Below is my initial attempt at it, but it seems to return nothing.

page = urllib2.urlopen(url)
soup = BeautifulSoup(page.read())
hours = soup.find_all("div", class_="lobbyHours")
print hours
like image 385
kchoi Avatar asked Dec 15 '25 06:12

kchoi


1 Answers

That url redirects, which is why soup.find_all("div", class_="lobbyHours") returns nothing. There is no div with that class on the page you're redirecting to.

By monitoring network traffic with Firefox's Firebug, I found that the url you are requesting actually returns a 301 Moved Permanently status code. Fortunately, even a 301 status code, in the response headers provides a Location header. In this case:

'http://locators.bankofamerica.com/locator/locator/LocatorAction.do?shouldTest=true'

Which is the branch-locator page. You will have to start at this page, programmatically 'search' for the location(s) you would like, find the appropriate link, and perform a third request.

The site also uses cookies, so look into cookielib.

like image 119
That1Guy Avatar answered Dec 16 '25 19:12

That1Guy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!