Extract CSS from href links

前端 未结 1 1561
无人及你
无人及你 2021-01-25 23:00

This is the code to extract all the href links of a website by passing url of the website.

from BeautifulSoup import BeautifulSoup
import urllib2
import re
   ht         


        
相关标签:
1条回答
  • 2021-01-25 23:22

    You can loop through all the href links you have collected and get the css links in those pages.

    base_link='http://kteq.in/'
    hrefs = ['index']
    for link in hrefs:
        url = base_link+link
        html_page = urllib.request.urlopen(url)
        soup = BeautifulSoup(html_page,'html.parser')
        css_links = []
        for link in soup.findAll('link'):
            css_links.append(re.search(r"[A-Za-z0-9:/.-]+.css",link.get('href')))
    
    for i in css_links:
        if i==None:
            continue
       print(i[0])
    

    By going through the index page i got the following css links

    Output

    bootstrap/bootstrap.min.css
    https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css
    https://cdn.linearicons.com/free/1.0.0/icon-font.min.css
    //fonts.googleapis.com/css
    cards/card.css
    GalleryStyle/set1.css
    css/custom.css
    page-transition/css/component.css
    page-transition/css/animations.css
    https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css
    https://cdnjs.cloudflare.com/ajax/libs/slick-
    carousel/1.5.5/slick.min.css
    css/scrollpage.css
    css/changingtext.css
    css/color-slider.css

    0 讨论(0)
提交回复
热议问题