热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

如何在标签中找到最后一个数字-Howcanifindthelastnumberintags

forpassingthepaginationofasitewithpython,iwanttofindthelastpageofawebsite.iinspe

for passing the pagination of a site with python, i want to find the last page of a website. i inspect the element of the page by firebug

为了通过python传递网站的分页,我想找到一个网站的最后一页。我用firebug检查页面元素


Here the number that i want is 5

这里我想要的数字是5

1 个解决方案

#1


1  

Use a combination of a parser and regex:

使用解析器和正则表达式的组合:

from bs4 import BeautifulSoup
import re

html = your_html_here

soup = BeautifulSoup(html, "html5lib")
links = soup.findAll('a', text=re.compile('^\s*\d+\s*$'))
number = links[-1].string.strip()
print number
# 5

See a demo on ideone.com

在ideone.com上观看演示


推荐阅读
author-avatar
ar_wen2402851455
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有