Python BeautifulSoup網頁解析

  • 3177
  • 0

Python BeautifulSoup網頁解析

之前对web方面的东西了解太少了,所以之前想使用lxml去解析HTML总是很失败。不过退而求其次选择了效率稍微低一些的BeautifulSoup进行解析。

程序的主要作用是用于解析VUPEN提供ZeroDay Vulnerability Infomation。

from BeautifulSoup import BeautifulSoup
import urllib2,re

def Get0dayInfo():
    data = urllib2.urlopen("http://www.vupen.com/english/zerodays/").read()
    soup = BeautifulSoup(data)
    alltags = soup.findAll(attrs={'style' : 'FONT-WEIGHT: 700; FONT-SIZE: 8pt'}) #支持re正则
    for tag in alltags:
        print tag.string
    

if __name__ == "__main__":
    Get0dayInfo()

 

 

------------------------------

文章的授權使用CC BY-ND2.5協議。凡是標示“轉載”的文章,均來源於網絡並儘可能標註作者。如果有侵犯您的權益,請及時聯繫刪除或者署名、授權。


Gtalk/Email: cmd4shell  [at]  gmail.com