ruby - Ruby - 具有自定义文件名的 Watir 保存文件
问题描述
如果我有以下 HTML:
<a class="name" title="file_name" href="/somelink>NAMEOFFILE</a>
<div class="profile">
<img class="FFVAD" decoding="auto" style="" sizes="496px" src="https://websitename.com/054a89a69181e68399c756d746f3b996/followme.jpg">
</div>
如何使用 Watir 保存下载并使用链接标题保存图像。所以文件followme.jpg,将被下载并保存为title_name.jpg
解决方案
抱歉,我最后想出了这个。我将元素的标题存储到一个字符串中,然后在调用文件写入时使用该字符串。
@image_src = @browser.div(:class => "profile").image(:class => "FFVAD").src
@userimage = @browser.link(:class => "name").text
@filename = "./folder/#{@userimage}.jpg"
File.open(@filename, 'wb') do |f|
f.write open(@image_src).read
end
推荐阅读
- ios - 索引还是标签?对于多个复选框作为 IBOutletCollection 中的按钮
- c# - C# foreach 语句不能对变量进行操作
- javascript - Javascript:创建一个动态表,第一行的列标题和第一列的行标题
- django - 如何将 datepicker 和 timepicker 添加到 Django forms.SplitDateTimeField?
- android - 调用 startActivityForResult 后检测进程死亡
- database - 聚合。我想计算 mongo 中的记录,然后我想将该计数乘以不同集合中的字段
- reactjs - 在 API 响应中映射数组值以进行条件检查
- python - 模块导入类函数
- android - 在没有生命周期所有者的情况下使用 LiveData
- .htaccess - htaccess 路由与一个域和几个文件夹