0
我是新来的使用美丽和刮一般,所以我试图让我的脚湿说话。python beautifulsoup4解析谷歌财务数据
我想从这里得到的道琼斯工业平均指数信息的第一行: http://www.google.com/finance/historical?q=INDEXDJX%3A.DJI&ei=ZN_2UqD9NOTt6wHYrAE
虽然我可以读取数据,并打印(汤)输出的一切,我似乎无法到放下足够多。我将如何选择我保存到表格中的行?第一排怎么样?
非常感谢您的帮助!
import urllib.parse
import urllib.request
from bs4 import BeautifulSoup
import json
import sys
import os
import time
import csv
import errno
DJIA_URL = "http://www.google.com/finance/historical?q=INDEXDJX%3A.DJI&ei=ZN_2UqD9NOTt6wHYrAE"
def downloadData(queryString):
with urllib.request.urlopen(queryString) as url:
encoding = url.headers.get_content_charset()
result = url.read().decode(encoding)
return result
raw_html = downloadData(DJIA_URL)
soup = BeautifulSoup(raw_html)
#print(soup)
table = soup.findAll("table", {"class":"gf-table historical_price"})
嗨,我应该使用.find和.find_all时? – user1357015
'.find()'仅查找* first *匹配或返回'None','.find_all()'返回0个或更多匹配的列表。 –
太好了。这真的有帮助。是row.th特定于beautifulsoup?以前从未见过。 – user1357015