bs4 soup.select()里面的网页标签怎么看啊
bs4 soup.select()里面的网页标签怎么看啊 建议用 re 简单说就是看尖括号html='''<html><head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title>新闻中心首页_新浪网</title>
<meta name="keywords" content="新闻,时事,时政,国际,国内,社会,法治,聚焦,评论,文化,教育,新视点,深度,网评,专题,环球,传播,论坛,图片,军事,焦点,排行,环保,校园,法治,奇闻,真情">
<meta name="description" content="新浪网新闻中心是新浪网最重要的频道之一,24小时滚动报道国内、国际及社会新闻。每日编发新闻数以万计。">
<meta name="HandheldFriendly" content="true">
<meta content="always" name="referrer">
<link rel="mask-icon" sizes="any" href="//www.sina.com.cn/favicon.svg" color="red">
<link rel="alternate" type="application/rss+xml"title="新闻中心_新浪网" />
<meta content="always" name="referrer">
<meta name="stencil" content="PGLS000023" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
<link rel="apple-touch-icon" href="//i0.sinaimg.cn/dy/news3.png" />
<div class="channelHead">
<div class="cheadTopbar" id="blk_cheadTopbar_01" data-sudaclick="newsstdhead">
<div class="cheadTopbarLink" style="overflow: visible;">
<astyle="float:left">新浪首页</a>
<div class="pageReview" id="blk_syhg_01" style="z-index:1;float:left;margin-left:10px;border:0 none;padding:0">
<form name="pageReview" onsubmit="return false">
<select name="channel" class="pr_ch">
<option value="news" selected="selected">新闻</option>
<option value="sports">体育</option>
<option value="tech">科技</option>
<option value="finance">财经</option>
<option value="ent">娱乐</option>
<option value="auto">汽车</option>
</select>
<input type="text" readonly class="pr_date" name="date" value="载入中,请稍候..." />
<select name="time" class="pr_time">
<option value="am" selected="selected">9:00</option>
<option value="pm">21:00</option>
</select>
</form>
<div class="dateView" id="dataView" style="top:32px;"></div>
</div>
<div class="nav-mod-1 nav-w">
<ul>
<li><atarget="_blank"><b>汽车</b></a></li>
<li style="width:36px;"><atarget="_blank">报价</a></li>
<li><atarget="_blank">买车</a></li>
<li><atarget="_blank">新车</a></li>
</ul>
</div>
'''
from bs4 import BeautifulSoup
soup = BeautifulSoup(html,'html.parser')
result1 = soup.select('title')
print(result1)
print('------------------------------')
result2 = soup.select('input')
print(result2)
print('------------------------------')
result3 = soup.select('li')
print(result3)
print('------------------------------')
result4 = soup.select('option')
print(result4)
print('------------------------------')
result5 = soup.select('form')
print(result5)
print('------------------------------')
result6 = soup.select('a')
print(result6)
print('------------------------------')
可以看看这个帖子
https://fishc.com.cn/thread-184355-1-1.html
页:
[1]