簡體   English   中英

Python獲取所有CSS鏈接

[英]Python get all the CSS links

我開始使用cssutils庫,並且想做類似lxml.html庫函數“ iterlinks()”的內容,總而言之,我只想獲取css文件中的所有鏈接。 我想自己做,但我不知道這樣做是否做得好:

sheet = cssutils.parseString("http://example.com/style.css")
links = []
for rule in sheet.cssRules:
    for child in rule.style.children():
        value = child.propertyValue
        for i in range(value.length):
            if isinstance(i, cssutils.css.URIValue):
                links.append(i)

我想知道是否有更清潔的方法,即使有替代庫

cssutils為此提供了一種方法-使用getUrls

它將遍歷一個規則或整個樣式表,並返回找到的所有URL。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM