2017-06-19 8 views
-1

私はPythonを使い始めました。テーブルを掻き取ろうとしています... http://www.dramexchange.com/TableIn Pythonをスクラップする方法

まだ成功していません。

import requests, bs4 
r = requests.get('http://www.dramexchange.com/') 
soup = bs4.BeautifulSoup(r.text, 'lxml') 
for table in contents.find_all(class_='tb_NationalDramSpotPrice'): 
title = table.find(class_='title').text 
for tr in table.find_all('tr'): 
    _, Item, Daily High, Daily Low. Session High. Session Low. Session Average, Session Change = [td for td in tr.stripped_strings] 
    print(Item, Daily High, Daily Low. Session High. Session Low. Session Average, Session Change) 

ヘルプがありますか?

+0

あなたの問題は何ですか? –

答えて

0

あなたが実際にあなたの最初のイテレータに正しい変数を参照していないように見える起動するには:あなたは、変数contentsfind_all()を呼び出している

soup = bs4.BeautifulSoup(r.text, 'lxml') 
for table in contents.find_all(class_='tb_NationalDramSpotPrice'): 

お知らせ、ないのsoupにする前に宣言した通り。

私は実際にあなたがこすりしようとしているサイトに引き出すために余分なステップを行って、それが実際には「tb_NationalDramSpotPrice」のクラスが含まれていませんが、その名前の ID。それは、さらなる問題を加えるだろう。

関連する問題