Python网络爬虫没有输出
问题描述:
我试图创建我的第一个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)
答
你的问题奠定了在该行
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'
。
您可以在'plain_text = source_code.text'后面添加'print(plain_text)'语句并发布结果吗? – kvorobiev
它打印所有网站的文本,类别等(所有来自检查元素的文本) – pijasas
什么是期望的输出? –