zoukankan      html  css  js  c++  java
  • 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") #soup = BeautifulSoup(htmlhandle, "html.parser")
    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 += '
    '+title.text
            elif '.trigger' in title.text:
                apex_trigger += '
    '+title.text
            elif '.object' in title.text:
                custome_object += '
    '+title.text
            elif '.profile' in title.text:
                profile += '
    '+title.text
            else:
                others += '
    '+title.text
                
    print ('apex_class:
    '+apex_class);
    print ('apex_trigger:
    '+apex_trigger);
    print ('custome_object:
    '+custome_object);
    print ('profile:
    '+profile);
    print ('others:
    '+others);
  • 相关阅读:
    2016 年末 QBXT 入学测试
    Codevs 3409 搬礼物
    寻找子串位置
    Balanced Lineup
    统计难题
    爱在心中
    传话
    火柴排队
    新斯诺克
    排序
  • 原文地址:https://www.cnblogs.com/iwangzheng/p/13389698.html
Copyright © 2011-2022 走看看