1.利用Beautiful Soup去抓取p标签下class=jstest的内容
import io
import sys
import bs4 as bs
import urllib.request # 改变标准输出的默认编码为utf-8
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf8') # 获取该页面编码并解码成utf-8
sauce = urllib.request.urlopen(
'http://flask.showerlee.com/scrapingtest/').read().decode('utf-8') # 利用BS抓取页面源代码,并利用lxml规范格式
soup = bs.BeautifulSoup(sauce, 'lxml') js_test = soup.find('p', class_='jstest') print(js_test.text)
参考:http://www.showerlee.com/archives/2109