デフォルトコード
		
     状態:-
     閲覧数:1,062
		 投稿日:2017-10-23
		 更新日:2017-11-11
     
  
	
 				
	
 			
			 			▼index.py
▼index.py
Apacheログ
▼/var/log/httpd/
    
   
    
for link in bsObj.findAll("a", href=re.compile("^(/wiki/)")):
    if 'href' in link.attrs:
        if link.attrs['href'] not in pages:処理終了しないため、下記のように書き換えたら問題発生
▼index.py
link = bsObj.findAll("a", href=re.compile("^(/wiki/)"))
for i in range(5):
    if 'href' in link.attrs:エラーメッセージ
Apacheログ
▼/var/log/httpd/
[error]     "ResultSet object has no attribute '%s'. You're probably treating a list of items like a single item. Did you call find_all() when you meant to call find()?" % key
[error] AttributeError: ResultSet object has no attribute 'attrs'. You're probably treating a list of items like a single item. Did you call find_all() when you meant to call find()?
[error] AttributeError: ResultSet object has no attribute 'attrs'. You're probably treating a list of items like a single item. Did you call find_all() when you meant to call find()?
エラー原因 / エラー対応 / 修正後コード
エラー原因
find_all()で返ってくるのはオブジェクトのリスト
エラー対応
案A.find()を使用
案B.find_all()で返ってきたリストをforループを使用して処理
修正後コード
▼index.py
link = bsObj.find("a", href=re.compile("^(/wiki/)"))
for i in range(5):
    if 'href' in link.attrs: