html page as follows
<tr style="background-color:#fff;">
<td colspan="2" align=left valign="top">
<table id="zoom2" width="94%" border="0" cellspacing="0" cellpadding="0" style="margin:0 auto">
<!--startprint-->
<tr>
<th scope="col" id="DetailTilte">
<h1>微博客信息服务管理规定</h1>
</th>
</tr>
<tr>
<td scope="col" id="DetailContent">
usage:
def get_title(url):
resp = urllib.request.urlopen(url)
html = resp.read()
bs = BeautifulSoup(html, "html.parser")
title = bs.find('th', id='DetailTilte').h1.get_text()
return title
bs.find first parameter name tag may be 'a', 'p' or the like, the code looking for a label or tag p
Followed by a property can be id, can be a name, or some other property, I am here to fill in the id = 'DetailTitle'
Will be finished after
<th scope="col" id="DetailTilte">
< H1> micro-blog service management requirements Information </ h1>
</th>
Such a string, we need to get this th h1 tag inside, so the h1 to put forward, and get his copy
h1.get_text()
Original link: https: //blog.csdn.net/lynn_coder/article/details/79509863