

随便在该站点搜索药品“氟氯西林钠阿莫西林胶囊”,查看生成结果页面的源代码(如下):







其中myLog是一个自定义模板,其实就是对logging模板的简单格式化,Python代码如下:






1
的这一段之中,有我们需要的页码值,而我们只需要最后一页,也就是最大值。



1 if len(tagpage) == 0:
2 page = 0
3 else:
4 try:
5 page = int(tagpage[-1].get_text().strip())
6 except:
7 page = int(tagpage[-2].get_text().strip()





明确了吗·!自己可以尝试一下!