
你还在为写 CSS 选择器、XPath 写到头秃吗?
一个网页改版,所有选择器全废;一个站点结构不同,代码复制粘贴还要重写;好不容易写好,反爬一变又抓不到……
别卷了。今天这个 Python 库,直接把你想要的一个样本喂给它,它自己就学会规则,然后自动把同类型的东西全抓回来。零选择器、零 XPath、几行代码就能跑。
它就是 AutoScraper。
一句话:AutoScraper = 你给一个"想要的结果"当例子,它自动理解页面规则,然后举一反三批量抓相似内容。

传统爬虫 vs AutoScraper 的核心区别:
传统:你教浏览器"怎么找"
写 BeautifulSoup 选 .title、.price,或者 Scrapy 里写 XPath,网页结构一换就 404/空值/报错。
AutoScraper:你告诉它"想要什么"
比如你想要某个 StackOverflow 标题、某只股票的价格,直接把它作为 wanted_list 样本。它会自动学习页面里哪些元素跟这个样本"长得像",然后自动返回一堆相似的。
还能"精确复刻"
如果是价格、特定字段,用 get_result_exact 按你想要的顺序和位置原样返回,保证字段不串位。
1安装
就一行:
pip install autoscraper
2给一个样本,让它自己学 以 StackOverflow 为例,你想抓某个问题页下的"相关问题标题",只需告诉它一个标题:
from autoscraper import AutoScraper
url = 'https://stackoverflow.com/questions/2081586/web-scraping-with-python'
# 你"想要的"一个样本
wanted_list = ["What are metaclasses in Python?"]
scraper = AutoScraper()
result = scraper.build(url, wanted_list)
print(result)
输出直接是一堆相似标题:
['How do I merge two dictionaries in a single expression in Python?',
'How to call an external command?',
'What are metaclasses in Python?',
'Does Python have a ternary conditional operator?',
...]3换任意页面,自动复用规则
同一个 scraper 对象,拿到新 URL 继续抓:
scraper.get_result_similar(
'https://stackoverflow.com/questions/606191/convert-bytes-to-a-string'
)它会自动把新页面里类似位置、类似结构的标题全抓出来。你完全不需要再写任何选择器。
想抓实时股价?给一个样本价格,它自动学会这个页面里价格字段的位置:
url = 'https://finance.yahoo.com/quote/AAPL/'
wanted_list = ["124.81"] # 样本价格
scraper = AutoScraper()
scraper.build(url, wanted_list)
# 抓其他股票
scraper.get_result_exact('https://finance.yahoo.com/quote/MSFT/')
✅ 支持代理和自定义请求头— 通过request_args传 requests 参数,轻松过反爬。
✅模型可以保存复用—scraper.save('yahoo-finance')后下次load,不用重新学。
✅轻量— 纯 Python,MIT 协议,学习和运行时都不重。
✅GitHub 7.6K+ Star — 小身材,社区认可度很高。