2017-09-29 37 views
1

私は、次のコードからデータを抽出したい返さない:Beautifulsoupは()BeautifulSoupを使用して、何も

<div class="property-tag-container"> 
    <span class="c-prop-tag2">距离8号线市光路站284米</span> 
    <span class="c-prop-tag2">满五</span> 
    <span class="c-prop-tag2">有钥匙</span> 
</div> 

を次のように私が使用しているコードは次のとおりです。

for i in range (1,3): 
    if i == 1: 
      i = str(i) 
      a = (url + page + i + '/') 
      r = requests.get(url=a, headers=headers) 

      html = r.content 
      print(type(html),html) 
    else: 
      i = str(i) 
      a = (url + page + i + '/') 
      r = requests.get(url=a, headers=headers) 
      html2 = r.content 
      html = html + html2 

lj=BeautifulSoup(html,'html.parser') 
subway=lj.find_all('div',attrs={'class':'property-tag- 
container'},limit=None) 
sb=[] 
for c in subway: 

    subway=c.string 
    sb.append(subway) 
print(len(sb),sb) 

しかし、何もされていません

[なし]、[なし]、[なし]、[なし]、[なし]、[なし]、[なし]のリストには、次のような出力があります。なしなしなしなしなしなしなしなしなしなしなしなしなしなしなしなしなしなしなしなしなしなしなしなしなしなしなしなしなしなしなしなしなしなしなしなしなしなしなしなしなしなしなしなしなしなしなしなしなしなしなしなしなしなしなしなしなしなしなしなしなしなしなしなし、なし]

答えて

1

は一つだけdivそのクラスではありませんし、そのstring属性がNoneです。

これを試してみてください:

for c in subway: 
    subway=c.get_text() 
    sb.append(subway) 
+0

感謝を!それは今働く – Lingjun

関連する問題