2017-10-15 116 views
0

我試圖創建我的第一個python網絡爬蟲(從newboston學到它)。我沒有得到任何錯誤消息,但也沒有輸出.. 繼承人我的代碼:Python網絡爬蟲沒有輸出

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

你的問題奠定了在該行

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

根據docs秒參數attrs應與對字典像{'attr_name': 'attr_value'}{'atl '}set。另外,我認爲你的意思是'alt',而不是'atl'。嘗試使用

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

有沒有頁面上'a'元素與屬性'alt'