python - 从段落中提取整数
问题描述
我正在尝试仅从该段中提取费用金额,但我遇到了问题。有两笔费用,我想要其中两笔。这是我的代码:http://www.reading.ac.uk/ready-to-study/study/subject-area/modern-languages-and-european-studies-ug/ba-spanish-and-history。 aspx
fees_div = soup.find('div', class_='Fees hiddenContent pad-around-large tabcontent')
if fees_div:
fees_list = fees_div.find_all('\d+','p')
course_data['Fees'] = fees_list
print('fees : ', fees_list)
解决方案
试一试:
import re
import requests
from bs4 import BeautifulSoup
r = requests.get('http://www.reading.ac.uk/ready-to-study/study/subject-area/modern-languages-and-european-studies-ug/ba-spanish-and-history.aspx')
soup = BeautifulSoup(r.text,'html.parser')
item = soup.find(id='Panel5').text
fees = re.findall(r"students:[^£]+(.*?)[*\s]",item)
print(fees)
输出:
['£9,250', '£17,320']
推荐阅读
- json - POSTMAN - Visalize 定制的 JSON 文件
- python - importlib 不适用于子目录中的文件
- java - 如果请求来自,是否可以获得域或 IP 地址?
- iframe - DTM 跟踪 iframe 内的非 youtube 视频
- vue.js - 我如何将 Newrelic 与 Nuxt.js 一起使用
- java - JSON 解析错误:无法反序列化 START_ARRAY 令牌中的实例
- java - JUnit:如何通过构造函数创建具有依赖注入的测试类
- c# - 如果未经授权,如何本地化错误消息
- r - R 中的 dplyr 包:subset() 函数按月对数据帧进行子集化;错误 -<0 行>(或 0 长度行名称)
- c++ - 对字符串的真实条件检查