【发布时间】:2015-03-08 14:50:09
【问题描述】:
我一直在观看 thenewboston 关于如何制作网络爬虫的 3 个视频。似乎它们已经过时并且链接不存在。如果有人能完成本教程的第一部分,我将不胜感激。这是我所到之处。我尝试了不同的网站,但无济于事。
import requests
from bs4 import BeautifulSoup
def my_spider(max_pages):
page = 1
while page <= max_pages:
url = """Here I tried different websites""" + str(page)
source_code = requests.get(url)
plain_text = source_code.text
soup = BeautifulSoup(plain_text)
for link in soup.findALL("a", {"class" : "item-name"}):
href = """example site like following: https://example.com""" + link.get("href")
print(href)
page += 1
print(my_spider(2))
使用此代码,例如,我想爬到该站点以获取标题链接或类似内容。
仅供参考,这是视频。 https://www.youtube.com/watch?v=sVNJOiTBi_8&list=PL6gx4Cwl9DGAcbMi1sH6oAMk4JHw91mC_&index=26
教程25-27
提前致谢!
【问题讨论】:
-
调试了好久才发现问题所在。我应该 findAll 而不是 findALL。这就像****一样麻烦
标签: python python-3.x web-crawler