Beautiful Soup 解析html表格示例


from 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'

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM