python - Python:BeautifulSoup - 从 location.href= 中提取值
问题描述
我遇到了一个问题声明,我需要从代码中打印键“location.href=”的值“input.php?id=293”。
<script>location.href="input.php?id=293";</script>
我已经尝试了下面的代码,但最终卡住了。
import requests
from bs4 import BeautifulSoup
import re
url = https://localhost/sample.php
response = requests.get(url)
soup = BeautifulSoup(response.text, features="lxml")
value = soup.find_all(text=re.compile(r'location.href'))
print (value)
任何帮助将不胜感激。
解决方案
可以这样解决:
from bs4 import BeautifulSoup
data = BeautifulSoup('<script>location.href="input.php?id=293";</script>')
data.get_text()[15:-2]
推荐阅读
- python - Django:如何将两个或多个 FBV 渲染到一个模板中
- google-sheets - 通过 google-sheets 中的 xpath 在网站中搜索字符串后获取下一个文本的值
- ecmascript-6 - 转译 node-fetch 要求返回错误
- javascript - 如何使用 for 循环或数组填充 angularjs 列表?
- phaser-framework - 我怎样才能只放一次炸弹,直到它在物理街机池中爆炸?
- sql - SQL 左连接日期过滤器
- microsoft-graph-api - 用于多个用户的 Graph API Calendar getSchedule
- python-3.x - 重新安装python CentOS8,错误:找不到平台独立库
- c# - 如何将项目添加到 DataGridView 并在输入后自动对其进行排序?
- facebook - Facebook 开发者账户变更