【发布时间】:2014-02-09 02:30:01
【问题描述】:
我不熟悉使用 beautifulsoup 和一般刮痧,所以可以这么说,我正试图弄湿我的脚。
我想从这里获取道琼斯工业平均指数的第一行信息: http://www.google.com/finance/historical?q=INDEXDJX%3A.DJI&ei=ZN_2UqD9NOTt6wHYrAE
虽然我可以读取数据并 print(soup) 输出所有内容,但我似乎还不够深入。我将如何选择保存到表中的行?第一行怎么样?
非常感谢您的帮助!
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"})
【问题讨论】:
标签: python beautifulsoup