我尝试创建我的第一个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)发布于 2017-10-15 18:47:13
你的问题就在这条线上
for link in soup.findAll('a', {'atl '}):根据文档的第二个论点,attrs应该是一个有像{'attr_name': 'attr_value'}这样对的字典。{'atl '}是set。而且,我认为你指的是'alt',而不是'atl'。试着使用
for link in soup.findAll('a'):页面上没有带有属性'a'的'alt'元素。
https://stackoverflow.com/questions/46758436
复制相似问题