2017-01-09 12 views
0

このページ(http://bobaedream.co.kr/cyber/CyberCar_view.php?no=652455&gubun=I)をクロールしているうちに、わかりにくいエラーメッセージが表示されます。PythonコードでHTML要素が見つかりません

divタグ(div class = 'rightarea')には、いくつかのタグがあります。しかし、データを読み込んで収集しようとすると、エラーメッセージが返されます(content_table1 = table.find_all( 'div'、class _ = 'information') 'ResultSet'オブジェクトには 'find_all'という属性がありません)。変わったことは、私のコードは、異なるリストページのこのデータ部分を収集するためのエラーメッセージを返しません。以下は

は私のコードです:

from bs4 import BeautifulSoup 
import urllib.request 
from urllib.parse import urlparse 
from urllib.parse import quote 
from selenium import webdriver 
import re 
import csv 

URL = 'http://bobaedream.co.kr/cyber/CyberCar_view.php?no=652455&gubun=I' 
res = urllib.request.urlopen(URL) 
html = res.read() 
soup = BeautifulSoup(html, 'html.parser') 

# Basic Information 
table = soup.find_all('div', class_='rightarea') 
print(table) 

# Number, Year, Mileage, Gas Type, Color, Accident 
content_table1 = table.find_all('div', class_='information') 

助けてください。

答えて

0
table = soup.find_all('div', class_='rightarea') # will return a list like [div_tag, div_tag, ...] 

table.find_all('div', class_='information')にeuqalです:tagオブジェクトはfind_all()を使用することができますfind_all()

for t in table: 
    t.find_all('div', class_='information') 
0
# Basic Information 
table = soup.find_all('div', class_='rightarea') 
print(table) 
を使用するよりも、のみ、あなたは、 table listを反復 div tagを取得する必要があります

[div_tag, div_tag, ...].find_all('div', class_='information') 

soup.findallはbs4.element.ResultSetを返します。 2つの項目があります。最初のものは "div"、クラス_ = '情報' "です。

(Pdb) type(table) 
<class 'bs4.element.ResultSet'> 
(Pdb) len(table) 
2 

(Pdb) table[0] 
<div class="rightarea">\n<div class="information">... 

(Pdb) table[1] 
<div class="rightarea">\n<div class="spectitle">... 

(Pdb) table[0].find_all('div', class_='information') 
[<div class="information">\n<dl>\n<dt>\n<span><em>5,480</em>.... 

したがって、スクリプトでは、この行を更新して機能させる必要があります。

content_table1 = table[0].find_all('div', class_='information') 
関連する問題