1. 首页
  2. 数据库
  3. 其它
  4. Python爬虫第一课选取标签内容

Python爬虫第一课选取标签内容

上传者: 2020-12-31 07:40:19上传 PDF文件 31.17KB 热度 21次
Python爬虫第一课,选取标签内容 获取标题`# from urllib.request import urlopen `# from urllib.error import HTTPError from bs4 import BeautifulSoup def getTitle(url): try: html = urlopen(url) except HTTPError as e: return None try: bsObj = BeautifulSoup(html.read()) title = bsObj.body.h1 except AttributeError as e:
下载地址
用户评论