python beautifulsoup获取特定html源码

beautifulsoup 获取特定html源码(无需登录页面)

import re
from bs4 import BeautifulSoup
import urllib2

url = 'http://www.cnblogs.com/vickey-wu/'
# connect to a URL
web = urllib2.urlopen(url)
# read html code
html = web.read()
# print html
soup = BeautifulSoup(html,'html.parser')
prety = soup.prettify()
# print prety
pointed_div = soup.findAll(name="div", attrs={"class":re.compile("forFlow")})    # 筛选标签为div且属性class为forFlow的源码
print pointed_div
posted @ 2017-05-11 23:18  随便了888  阅读(5319)  评论(0编辑  收藏  举报