python解析网页并下载css和js文件代码
代码语言:python
所属分类:web系统
代码描述:python解析网页并下载css和js文件代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
#!/usr/local/python3/bin/python3 # -*- coding: utf-8 -* import requests from bs4 import BeautifulSoup as bs #pip3 install requests bs4 from urllib.parse import urljoin # URL of the web page you want to extract url = "http://www.bfw.wiki" # initialize a session session = requests.Session() # set the User-agent as a regular browser session.headers["User-Agent"] = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.157 Safari/537.36" # get the HTML content html = session.get(url).content # parse HTML using beautiful soup soup = bs(html, "html.parser") # get the JavaScript files script_files = [] for script in soup.find_all("script"): if script.attrs.get("src"): # if the tag has the attribute 'src' script_.........完整代码请登录后点击上方下载按钮下载查看
网友评论0