0
我試圖從http://marine-transportation.capitallink.com/indices/baltic_exchange_history.html?ticker=BDI提取一表,而class和id
湊表雖然這似乎是很容易的,不可能對我來說,確定以這樣的方式,我可以刮它,我的表無法提取數據。任何一個都可以幫助您獲得正確的識別
import urllib3
import urllib.request
from bs4 import BeautifulSoup
import pandas as pd
import requests
import csv
import re
url = 'http://marine-transportation.capitallink.com/indices/baltic_exchange_history.html?ticker=BDI'
r = requests.get(url)
soup = BeautifulSoup(r.text, 'lxml')
col = row.find_all('td')
column_1 = col[0].string.strip()
#
date = []
closing_rate = []
#Here i need a reference to the correct table
table = soup.find()
for row in table.find_all('tr')[1:]:
col = row.find_all('td')
column_1 = col[0].string.strip()
date.append(column_1)
column_2 = col[1].string.strip()
closing_rate.append(column_2)
columns = {'date': date, 'closing_rate': ClosingRate}
df = pd.DataFrame(columns)
df.to_csv('Baltic_Dry.csv')
該頁面需要登錄 –