zl程序教程

您现在的位置是:首页 >  后端

当前栏目

Python 教程之使用 Autoscraper 轻松实现 Python 网页抓取

Python网页教程 实现 轻松 抓取 使用
2023-09-11 14:18:32 时间

今天我们来看看一个名为 Autoscraper 的 Python 包。Web 抓取是我在 Python 中最喜欢做的事情之一,但如果你是初学者,它可能会有点棘手。有很多包可以完成这项工作(即使是标准的 Python 也有可以管理 HTTP 请求的 Urllib),但今天我们将专注于 Autoscraper。

Autoscraper 是一款智能且快速的自动网页抓取工具,不需要任何 HTML 或 CSS 知识。虽然它不像其他软件包那样可定制,但它可以很快完成工作。对于初学者来说,这是一个很好的包,可以在不担心网页的 HTML 代码的情况下享受网络抓取的乐趣。

要求和目标

对于本教程,您需要:

  • Python 3.x
  • 自动刮板

要安装软件包,请在终端中运行以下行:

pip install autoscraper

2.代码

from autoscraper import AutoScraper

# Create the model
url = 'https://medium.com/@inzaniak'
wanted_list = ["Build a Web Scraping Python Project from Start to Finish", "5 things you need to learn as a Python beginner"]

scraper = AutoScraper()
result = scraper.build(url, wanted_list)
print(result)

# Save the model
scraper.save('scrapers/medium.json