Created
September 25, 2013 02:21
-
-
Save l34marr/6694394 to your computer and use it in GitHub Desktop.
ref http://jpython.blogspot.tw/2012/11/beautiful-soup-css-selector.html
tested on Ubuntu 12.04 Python 2.7.3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from bs4 import BeautifulSoup | |
import requests | |
r = requests.get("http://www.nasdaq.com/symbol/f/dividend-history") | |
data = r.content | |
soup = BeautifulSoup(data) | |
for i in range(1,31): | |
id_exdate = "#quotes_content_left_dividendhistoryGrid_exdate_"+str(i) | |
id_cash = "#quotes_content_left_dividendhistoryGrid_CashAmount_"+str(i) | |
id_decl = "#quotes_content_left_dividendhistoryGrid_DeclDate_"+str(i) | |
id_rec = "#quotes_content_left_dividendhistoryGrid_RecDate_"+str(i) | |
id_pay = "#quotes_content_left_dividendhistoryGrid_PayDate_"+str(i) | |
print soup.select(id_exdate)[0].string+', '+soup.select(id_cash)[0].string+', '+soup.select(id_decl)[0].string+', '+soup.select(id_rec)[0].string+', '+soup.select(id_pay)[0].string |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment