我需要来自 python selenium webdriver 中的网络调用的 JSON 数据,甚至需要来自网络调用的一个特定 URL 响应 JSON 数据。
这是我想要的示例数据的图像
我确实想要来自网络调用的 JSON 响应中的“Mobikwik Offer”。
任何人都可以帮助我解决这个问题,还建议获取此数据的替代选项。提前致谢。
我正在 Android 设备上的termux环境中运行 python 脚本,我希望能够检测到操作系统是 Android。
\n传统方法不起作用:
\n>>> import platform\n>>> import sys\n>>> print(platform.system())\n\'Linux\'\n>>> print(sys.platform)\n\'linux\'\n>>> print(platform.release())\n\'4.14.117-perf+\'\n>>> print(platform.platform())\n\'Linux-4.14.117-perf+-aarch64-with-libc\'\nRun Code Online (Sandbox Code Playgroud)\n还有哪些其他可用的 ootb 选项?
\n一个明显有用的选项是platform.machine()返回armv8\xe2\x80\x94 这不仅仅是 \'Linux\' 但它只是架构,而不是操作系统,并且它可能会返回误报,例如在树莓派上或其他基于arm的系统。
from yt_dlp import YoutubeDL
with YoutubeDL() as ydl:
ydl.download('https://youtu.be/0KFSuoHEYm0')
Run Code Online (Sandbox Code Playgroud)
这是产生输出的相关代码位。
我想做的是从下面的输出中获取倒数第二行,指定视频标题。
我尝试过一些变体
output = subprocess.getoutput(ydl)
Run Code Online (Sandbox Code Playgroud)
也
output = subprocess.Popen( ydl, stdout=subprocess.PIPE ).communicate()[0]
Run Code Online (Sandbox Code Playgroud)
我试图捕获的输出是这里的倒数第二行:
from yt_dlp import YoutubeDL
with YoutubeDL() as ydl:
ydl.download('https://youtu.be/0KFSuoHEYm0')
Run Code Online (Sandbox Code Playgroud)
yt-dlp 上还有关于如何从元数据中提取标题或将其包含在 YoutubeDL() 后面的括号中的文档,但我不太明白。
这是我用 python 制作的第一个项目的一部分。我缺少对许多概念的理解,任何帮助将不胜感激。
YouTube Data API v3 似乎缺少检查视频 ID 是否较短的功能。检查是否是短视频的另一种方法是检查以下公共 url 的响应代码:https://www.youtube.com/shorts/:videoId(303 = 常规视频,200 = 短视频),但这很容易导致速率限制,如果在 Cloudflare 等工作节点上使用, Google 会将请求标记为可疑。
还有其他方法来检查视频是否是短视频吗?
我们将 syslogd 设置为将来自几个不同服务器的所有日志发送到一台服务器中,全部发送到一个名为/var/log/centrallogs.
我们为此目录使用以下日志轮换配置:
/etc/logrotate.d/centrallogs:
/var/log/centrallogs/*log {
rotate 5
compress
missingok
notifempty
sharedscripts
postrotate
/etc/init.d/httpd restart > /dev/null 2>/dev/null || true
endscript
}
Run Code Online (Sandbox Code Playgroud)
在测试(使用logrotate -d centrallogs)中,LR 似乎没有尝试进行任何旋转。
这是输出(注意,我已经重命名了站点,但这是我所做的唯一更改):
rotating pattern: /var/log/centrallogs/*log 1048576 bytes (5 rotations)
empty log files are not rotated, old logs are removed
considering log /var/log/centrallogs/site1_access.log
log needs rotating
considering log /var/log/centrallogs/site1_error.log
log does not need rotating
considering log /var/log/centrallogs/site2_access.log
log needs rotating
considering log /var/log/centrallogs/site2_error.log
log needs rotating
considering log /var/log/centrallogs/site3_access.log
log …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个 Firefox 插件,当您单击特定按钮时,它可以自动运行 bash 命令。(始终是客户端)
现在我管理如何执行简单的命令,例如ls使用:
var child_process = require("sdk/system/child_process");
var ls = child_process.spawn('/bin/ls', ['-lh', '/usr']);
Run Code Online (Sandbox Code Playgroud)
我的问题是,我可以运行 bash 脚本吗?(.sh 文件)
例如:
var child_process = require("sdk/system/child_process");
var ls = child_process.spawn('/bin/ls', ['-lh', '/usr']);
Run Code Online (Sandbox Code Playgroud) 我找到了一个具有特定类的对象:
THREAD = TREE.find_class('thread')[0]
Run Code Online (Sandbox Code Playgroud)
现在我想获取<p>它的直接子元素的所有元素。
我试过:
THREAD.findall("p")
THREAD.xpath("//div[@class='thread']/p")
Run Code Online (Sandbox Code Playgroud)
但所有这些都返回<p>this 内的所有元素<div>,无论它<div>是否是它们最近的父元素。
我怎样才能让它发挥作用?
编辑:
示例 HTML:
<div class='thread'>
<p> <!-- 1 -->
<!-- Can be some others <p> objects inside, which should not be counted -->
</p>
<p><!-- 2 --></p>
</div>
<div class='thread'>
<p>[...]</p>
<p>[...]</p>
</div>
Run Code Online (Sandbox Code Playgroud)
脚本应该找到两个对象<p>,它们是 的子对象THREAD。我应该收到两个对象的列表,在示例 HTML 的注释中标记为“1”和“2”。
编辑2:
由于人们感到困惑,还有一个澄清:
THREAD是存储在变量中的一些对象,可以是任何 html 元素。我想找到 的<p>直接子对象THREAD。这些<p>元素不能位于THREAD任何位于其内部的元素的外部或内部THREAD。
我有一个程序需要读取电子邮件并验证它们是否来自本月,然后再继续。
我通过以下代码获取电子邮件信息
import email
import smtplib
import imaplib
mail = imaplib.IMAP4_SSL('redacted', 993)
mail.login(username, bytes(password).decode('utf-8')) #password is bytes that have been decrypted
msg_data2 = [] #My template allows for multiple email data to be appended
mailbox_data = mail.list()
mail.select('INBOX', readonly=True)
result, msg_ids = mail.search(None, f'(SEARCH CRITERIA REDACTED)')
lister = msg_ids[0].split()
most_recent = lister[-1]
result2, msg_data = mail.fetch(most_recent, '(RFC822)')
msg_data2.append(msg_data)
raw = email.message_from_bytes(msg_data[0][1])
Run Code Online (Sandbox Code Playgroud)
从这里,我可以从我的电子邮件中获取符合搜索条件的附件,以前,供应商会根据其工作运行的月份正确命名文件。现在有些不是,所以我试图检查电子邮件发送或接收的日期。
我知道如何通过git-crypt加密存储库中的文件:
echo "*.crypt.* filter=git-crypt diff=git-crypt" > .gitattributes
echo "supersecret info" > somethingTo.crypt.txt
git add .gitattributes somethingTo.crypt.txt
git crypt status # somethingTo.crypt.txt results encrypted
git commit
git push
Run Code Online (Sandbox Code Playgroud)
我知道如何使用git-lfs存储文件(在自托管的 GitLab 上;在项目设置中启用 LFS):
git lfs track somethingTo.crypt.txt
git add .gitattributes # updated LFS rule for tracked file
git commit
git push
Run Code Online (Sandbox Code Playgroud)
...但是,如何在同一个文件上使用它们呢?
即使在用于存储在 LFS 上的过滤器之前.gitattributes有用于加密的git-filter,该文件也不会被加密(报告“未加密”)。LFS 未跟踪的所有其他文件均已正确加密。git crypt status | grep somethingTo*.crypt.*
我想问题在于我somethingTo.crypt.txt现在只是存储库中的引用对象,而不是实际的(加密的)文件。但我希望(感谢 s git-filter)文件在被推送到LFS Store之前会被过滤/加密。 …
目标是将我的代码加密存储在 BitBucket 远程存储库上。有些东西应该处理加密和解密,所以我选择了 gcrypt 或完整的 git-remote-gcrypt。
我有一个配置了 SSH 密钥的 Bitbucket 帐户。
这是我尝试过的。
我从手册中复制了这些命令。
git remote remove cryptremote
git remote add cryptremote gcrypt::rsync://git@bitbucket.org/user/cryptremote.git
git config remote.cryptremote.gcrypt-participants "user"
git push cryptremote master
Run Code Online (Sandbox Code Playgroud)
安慰:
gcrypt:找不到存储库:rsync://git@bitbucket.org/user/cryptremote.git
gcrypt:设置新的存储库
协议版本不匹配 - 您的 shell 干净吗?
(有关说明,请参阅 rsync 手册页)
rsync 错误:compat.c(600) [sender=v3.2.3] 处的协议不兼容(代码 2)
错误:无法将某些引用推送到 'gcrypt::rsync://git @bitbucket.org/user/cryptremote.git'
python ×5
git ×2
android ×1
bash ×1
bitbucket ×1
centos6 ×1
email ×1
encryption ×1
firefox ×1
gcrypt ×1
git-crypt ×1
git-filter ×1
git-lfs ×1
javascript ×1
linux ×1
logrotate ×1
lxml ×1
os-detection ×1
python-3.x ×1
xpath ×1
youtube ×1
youtube-api ×1