如何使用 adblockparser 规则匹配 html tag.id 或 tag.class 名称?

How to match html tag.id or tag.class names using adblockparser rules?

from bs4 import BeautifulSoup
soup = BeautifulSoup(html_doc,'html.parser')
for tag in soup.find_all(True):
    print rules.should_block([TAG ID OR TAG CLASS])    

据我所知,Adblock 可以根据名称屏蔽 HTML 元素。

例如:

如果 div 的 ID 是 #ads,它将被阻止。

我怎样才能做类似的事情?

要阻止 class 名称,您需要过滤器

||domain.com##.classnamehere

要按 ID 阻止元素,您需要过滤器

||domain.com###IDnamehere

如果您想更好地理解过滤器,这里有一本很好的入门书:https://adblockplus.org/filters

如果您想了解哪些过滤器正在影响特定站点,这里有一个很好的过滤器搜索引擎:http://blockadblock.com/search-adblock-filters.php

将过滤器添加到 Python 解析器可能超出了这个答案的范围,但这里有很多很好的文档:https://github.com/scrapinghub/adblockparser