2017-10-15 11 views
0

私は最初のpython web crawlerを作成しようとしました(thenewbostonから学んでいます)。私はすべてのエラーメッセージを取得いけない、だけでなく、何も出力.. はHERESに私のコード:Python web crawler no output

import requests 
from bs4 import BeautifulSoup 

def sportpoint_spider(max_pages): 
    page = 1 
    while page <= max_pages: 
     url = 'http://www.sportpoint.lt/vyrams-1?page=' + str(page) 
     source_code = requests.get(url) 
     plain_text = source_code.text 
     soup = BeautifulSoup(plain_text, "html.parser") 
     for link in soup.findAll('a', {'atl '}): 
      href = link.get('href') 
      print(href) 
     page += 1 

sportpoint_spider(1) 
+0

'plain_text = source_code.text'の後に' print(plain_text) '文を追加して結果を投稿できますか? – kvorobiev

+0

すべてのウェブサイトのテキスト、クラスなどを印刷しました(検査要素のすべてのテキスト) – pijasas

+0

希望する出力は何ですか? –

答えて

2

あなたの問題は、第二引数attrsがペアと辞書でなければなりませんdocsに従って、このラインで

for link in soup.findAll('a', {'atl '}): 

を産むん{'attr_name': 'attr_value'}のようになります。 {'atl '}setです。また、'atl'ではなく、'alt'を意味すると思います。属性'alt'とページ上の'a'要素はありません

for link in soup.findAll('a'): 

を使用してみてください。

関連する問題