假期python学习第一日
2019-07-07 22:20 FriendG 阅读(222) 评论(0) 收藏 举报对于BS4的学习,还有五种过滤器: 字符串、正则表达式、列表、True、方法

import requests
from bs4 import BeautifulSoup
res = requests.get('https://mbd.baidu.com/newspage/data/landingsuper?context=%7B%22nid%22%3A%22news_9157052798299374832%22%7D&n_type=0&p_from=1')
res.encoding = 'utf-8'
html_doc = res.text
#soup =BeautifulSoup(html_doc,'html.parser')
#print(soup.title)
#soup =BeautifulSoup(html_doc,'lxml')
#print(soup.find_all('span'))
#自定义
def r(tag):
return tag.has_attr('class') and not tag.has_attr('id')
print(soup.find_all(r))
浙公网安备 33010602011771号