你知道html最常使用的标签有多少个

Q:你知道html最常使用的标签有多少个吗

A:30个左右


from bs4 import BeautifulSoup
import urllib.request
import urllib.parse


def html_download(url):
    if url is None:
        return None

    response = urllib.request.urlopen(url)
    if 200 == response.status:
        html = response.read()
        return html


def html_parse(url, html):
    soup = BeautifulSoup(html, "lxml")
    tags_all = set()
    tags_special = set()
    tags_normal = {"html", "head", "body", "meta",
                   "title", "link", "script", "div",
                   "img", "span", "a", "p"}   #基本上会用到的标签有12个
    for tag in soup.find_all(True):
        tags_all.add(tag.name)
        if tag.name not in tags_normal:
            tags_special.add(tag.name)
    print("tags_all=%s" % tags_all)
    print("url=%s, tags_all_length=%s" % (url, len(tags_all)))
    tags_len.append(len(tags_all))
    print("tags_special=%s" % tags_special)
    print("url=%s, tags_special_length=%s" % (url, len(tags_special)))
    print("---------------------------------------------------------------------\n")

if __name__ == "__main__":
    root_urls = ["https://www.360.cn/",
                 "https://www.apple.com/cn/",
                 "https://www.taobao.com/",
                 "https://www.microsoftstore.com.cn/",
                 "https://www.amazon.cn",
                 "https://github.com/",
                 "https://en.wikipedia.org/wiki/Main_Page",
                 "https://developer.mozilla.org/zh-CN/"]
    # 存放使用标签个数
    tags_len = []
    for url_item in root_urls:
        html_content = html_download(url_item)
        html_parse(url_item, html_content)

    print(tags_len)
    print(sum(tags_len)/len(tags_len))
    print("crawler end")

下面是输出结果:

tags_all={'ul', 'title', 'meta', 'html', 'input', 'link', 'button', 'dl', 'head', 'span', 'div', 'p', 'h2', 'script', 'body', 'img', 'dt', 'h3', 'a', 'style', 'li', 'form', 'i', 'dd', 'br', 'base'}
url=https://www.360.cn/, tags_all_length=26
tags_special={'button', 'dl', 'ul', 'h2', 'h3', 'input', 'dt', 'li', 'form', 'style', 'i', 'dd', 'br', 'base'}
url=https://www.360.cn/, tags_special_length=14
---------------------------------------------------------------------


tags_all={'ul', 'title', 'meta', 'html', 'input', 'link', 'button', 'h2', 'head', 'span', 'div', 'h3', 'aside', 'script', 'body', 'img', 'p', 'figure', 'h1', 'article', 'nav', 'a', 'style', 'footer', 'section', 'main', 'label', 'li', 'form', 'br'}
url=https://www.apple.com/cn/, tags_all_length=30
tags_special={'button', 'h2', 'ul', 'h3', 'aside', 'label', 'article', 'h1', 'li', 'figure', 'form', 'style', 'footer', 'section', 'br', 'input', 'main', 'nav'}
url=https://www.apple.com/cn/, tags_special_length=18
---------------------------------------------------------------------


tags_all={'ul', 'textarea', 'title', 'meta', 'html', 'input', 'b', 'link', 'h2', 'button', 'head', 'span', 'div', 'p', 'h3', 'script', 'body', 'img', 'h1', 'h4', 'a', 'style', 'strong', 'label', 'li', 'em', 's', 'form', 'h5', 'i', 'br', 'base'}
url=https://www.taobao.com/, tags_all_length=32
tags_special={'h2', 'button', 'ul', 'h3', 'br', 'label', 'input', 'li', 'textarea', 'em', 's', 'form', 'style', 'h5', 'i', 'h1', 'base', 'h4', 'strong', 'b'}
url=https://www.taobao.com/, tags_special_length=20
---------------------------------------------------------------------


tags_all={'ul', 'title', 'meta', 'html', 'input', 'link', 'head', 'span', 'div', 'p', 'script', 'body', 'img', 'h4', 'a', 'icon', 'u', 'li', 'em', 'form', 'br', 'del'}
url=https://www.microsoftstore.com.cn/, tags_all_length=22
tags_special={'ul', 'icon', 'u', 'li', 'em', 'form', 'br', 'input', 'h4', 'del'}
url=https://www.microsoftstore.com.cn/, tags_special_length=10
---------------------------------------------------------------------


tags_all={'ul', 'map', 'title', 'meta', 'html', 'area', 'input', 'b', 'link', 'head', 'span', 'div', 'h3', 'script', 'body', 'img', 'td', 'tr', 'table', 'a', 'style', 'hr', 'li', 'noscript', 'header', 'option', 'form', 'select', 'i'}
url=https://www.amazon.cn, tags_all_length=29
tags_special={'ul', 'h3', 'hr', 'map', 'li', 'noscript', 'header', 'option', 'td', 'form', 'style', 'select', 'i', 'tr', 'area', 'input', 'table', 'b'}
url=https://www.amazon.cn, tags_special_length=18
---------------------------------------------------------------------


tags_all={'ul', 'title', 'meta', 'path', 'html', 'input', 'link', 'button', 'dl', 'head', 'span', 'div', 'p', 'h2', 'h3', 'body', 'img', 'script', 'h6', 'h1', 'h4', 'nav', 'svg', 'a', 'g', 'style', 'label', 'li', 'header', 'line', 'form', 'defs', 'dd'}
url=https://github.com/, tags_all_length=33
tags_special={'ul', 'path', 'input', 'button', 'dl', 'h2', 'h3', 'h6', 'h1', 'h4', 'nav', 'svg', 'g', 'style', 'label', 'li', 'header', 'line', 'form', 'defs', 'dd'}
url=https://github.com/, tags_special_length=21
---------------------------------------------------------------------


tags_all={'ul', 'title', 'meta', 'html', 'input', 'b', 'link', 'h2', 'head', 'span', 'div', 'p', 'h3', 'script', 'body', 'img', 'td', 'tr', 'h1', 'table', 'a', 'small', 'label', 'li', 'noscript', 'form', 'i', 'br'}
url=https://en.wikipedia.org/wiki/Main_Page, tags_all_length=28
tags_special={'h2', 'ul', 'b', 'h3', 'br', 'label', 'li', 'td', 'noscript', 'small', 'form', 'tr', 'i', 'h1', 'input', 'table'}
url=https://en.wikipedia.org/wiki/Main_Page, tags_special_length=16
---------------------------------------------------------------------


tags_all={'ul', 'title', 'cite', 'meta', 'html', 'bdi', 'input', 'link', 'button', 'h2', 'head', 'span', 'div', 'p', 'h3', 'script', 'body', 'h1', 'nav', 'a', 'footer', 'main', 'time', 'label', 'li', 'noscript', 'header', 'option', 'form', 'select', 'i', 'br'}
url=https://developer.mozilla.org/zh-CN/, tags_all_length=32
tags_special={'ul', 'cite', 'bdi', 'input', 'button', 'h2', 'h3', 'h1', 'nav', 'footer', 'main', 'time', 'label', 'li', 'noscript', 'header', 'option', 'form', 'select', 'i', 'br'}
url=https://developer.mozilla.org/zh-CN/, tags_special_length=21
---------------------------------------------------------------------


[26, 30, 32, 22, 29, 33, 28, 32]
29.0
crawler end

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值