使用BeautifulSoup无法抓取目标行:需从student-login类提取含username/password的行
爬取需求与现有开发状态
- 目标爬取页面地址:
https://www.champlain.edu/current-students - 基础定位逻辑:在目标页面源码中查找类名为
student-login的元素块 - 进阶实现需求:在已定位的
student-login元素块范围内做二次内容检索,仅返回包含username或password字符串的完整行内容 - 当前可实现效果:现有代码可正常运行,能够输出
student-login类元素块的全部内部内容,但暂未实现精准筛选逻辑,无法过滤出符合目标字符串规则的内容 - 运行输出参考:当前代码的实际输出结果截图存储地址为
https://i.sstatic.net/aGE0x.jpg,截图标注为“当前输出效果”
现有可正常运行的代码
from urllib.request import urlopen from bs4 import BeautifulSoup html = urlopen('https://www.champlain.edu/current-students') bs = BeautifulSoup(html.read(), 'html.parser') soup = bs.find(class_='student-login') print(soup)
内容的提问来源于stack exchange,提问作者zeusbella
相关产品推荐
相关产品推荐

