BEAUTIFULSOUP解析本地文件

import requests

from bs4 import BeautifulSoup

apex_class = ''

apex_trigger = ''

custome_object = ''

profile = ''

others = ''

path = '/Users/aaa/Downloads/aaa.htm'

htmlfile = open(path, 'r')

htmlhandle = htmlfile.read()

soup = BeautifulSoup(htmlhandle, "lxml")

titles = soup.find_all("a", class_="link-gray-dark")

for title in titles:

    if 'src' in title.text:

        if '.cls' in title.text:

            apex_class += '\n'+title.text

        elif '.trigger' in title.text:

            apex_trigger += '\n'+title.text

        elif '.object' in title.text:

            custome_object += '\n'+title.text

        elif '.profile' in title.text:

            profile += '\n'+title.text

        else:

            others += '\n'+title.text


print ('apex_class:\n'+apex_class);

print ('apex_trigger:\n'+apex_trigger);

print ('custome_object:\n'+custome_object);

print ('profile:\n'+profile);

print ('others:\n'+others);

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。