python beautifulsoup获取特定html源码

时间:2022-07-13 22:41:44
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