正则匹配不成功
print link_node.name,link_node['src']
AttributeError: 'NoneType' object has no attribute 'name'
#coding:utf-8
'''
Created on 2016年9月4日
@author: freedom fighter
'''
import re
from bs4 import BeautifulSoup
html_doc=""" <script src="/site/1/js/top.js" type="text/javascript"></script>
<script type="text/javascript">topContent()</script>
<script src="/site/1/js/bottom.js" type="text/javascript"></script>
<script type="text/javascript">bottomContent()</script>
<script src="/js/libs/jquery-1.8.3.min.js" type="text/javascript"></script>
<script src="/js/libs/slides.min.jquery.js" type="text/javascript"></script>
<script type="text/javascript">
"""
soup=BeautifulSoup(html_doc,'html.parser',from_encoding='utf-8')
print "获取所有Scripts"
links=soup.find_all('script')
for link in links:
print link.name,link['type'],link.get_text
print "获取bottom.js这个脚本"
link_node=soup.find('script',src='/site/1/js/bottom.js')
print link_node.name,link_node['src']
print "正则匹配"
link_node=soup.find('script',re.compile(r'ide'))
print link_node.name,link_node['src']