Beautiful Soup 解析html表格示例
2021-06-09 22:01
标签:imp page html 解析 name blog com erro nbsp Beautiful Soup 解析html表格示例 标签:imp page html 解析 name blog com erro nbsp 原文地址:http://www.cnblogs.com/wangyufu/p/7298428.htmlfrom bs4 import BeautifulSoup
import urllib.request
doc = urllib.request.urlopen(‘http://www.bkzy.org/Index/Declaration?intPageNo=1‘)
doc = doc.read().decode(‘utf-8‘)
soup = BeautifulSoup(doc, "html.parser")
school = 0
pro_code = 1
pro_name = 2
xuewei = 3
pdf = 4
# find_all 查到所有tr列表
for tr in soup.find_all(‘tr‘,):
# 在每个tr找td
td = tr.find_all(‘td‘)
try:
print(‘%s_%s_%s_%s.pdf‘ % (
td[school].text.strip(),
td[pro_code].text.strip(),
td[pro_name].text.strip(),
td[xuewei].text.strip())
,td[pdf].find(‘a‘)[‘href‘])
except IndexError as e:
pass
参考文档 = ‘http://cuiqingcai.com/1319.html‘
上一篇:Python列表等长度分割
下一篇:jquery 下载
文章标题:Beautiful Soup 解析html表格示例
文章链接:http://soscw.com/index.php/essay/92856.html