【问题标题】:How do I build a Web Crawler using Python 3?如何使用 Python 3 构建 Web 爬虫?
【发布时间】: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


【解决方案1】:

有一些 python 3 到 web 抓取的库,但没有一个像 python 2 库 Scrapy 那样受欢迎,

一些可用的python 3 Web Scrapers/Crawler: 1-盛况 2- 鼠科 3-pyburrow

我自己没用过,但你可以在 github 上查看他们的网站或源代码,以便更好地了解你如何使用它们

【讨论】:

  • Scrappy 1.1 现在开始支持 Python3。
猜你喜欢
  • 2012-02-20
  • 2019-11-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-05-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多