linux C 从命令行下载图像
发布时间:2023-12-13 16:49:40 所属栏目:Linux 来源:DaWei
导读: 我想下载第n个图像,谷歌给我的命令行,就像命令wget
要搜索[某事]的图像,我只需转到页面https://www.google.cz/search?q=[something]u0026amp;tbm=isch,但如何获取第n个搜索结果的网址,
要搜索[某事]的图像,我只需转到页面https://www.google.cz/search?q=[something]u0026amp;tbm=isch,但如何获取第n个搜索结果的网址,
我想下载第n个图像,谷歌给我的命令行,就像命令wget 要搜索[某事]的图像,我只需转到页面https://www.google.cz/search?q=[something]u0026amp;tbm=isch,但如何获取第n个搜索结果的网址,以便我可以使用wget的? 解决方法 第一次尝试首先,您需要设置用户代理,所以Google将授权搜索的输出.然后我们可以查找图像并选择所需的图像.为了完成这一点,我们插入缺少的换行符,wget将在一行中返回google搜索,并过滤链接.文件的索引存储在变量count中. $count=10 $imagelink=$(wget --user-agent 'Mozilla/5.0' -qO - "www.google.be/search?q=something&tbm=isch" | sed 's/</n</g' | grep '<img' | head -n"$count" | tail -n1 | sed 's/.*src="https://www.0779zz.com/html/zhonghe/fwq/Linux/20210220/([^"]*)".*/1/') $wget $imagelink该图像现在将在您的工作目录中,您可以调整最后一个命令并指定所需的输出文件名. 您可以在shell脚本中对其进行总结: #! /bin/bash count=${1} shift query="$@" [ -z $query ] && exit 1 # insufficient arguments imagelink=$(wget --user-agent 'Mozilla/5.0' -qO - | "www.google.be/search?q=${query}&tbm=isch" | sed 's/</n</g' | grep '<img' | head -n"$count" | tail -n1 | sed 's/.*src="https://www.0779zz.com/html/zhonghe/fwq/Linux/20210220/([^"]*)".*/1/') wget -qO google_image $imagelink使用示例 $ls Documents Downloads Music script.sh $chmod +x script.sh $bash script.sh 5 awesome $ls Documents Downloads google_image Music script.sh现在,google_image应该包含第五个谷歌图像,当寻找’awesome’.如果您遇到任何错误,请告诉我,我会照顾他们. 更好的代码 该代码的问题是它以低分辨率返回图片.一个更好的解决方案如下: #! /bin/bash # function to create all dirs til file can be made function mkdirs { file="$1" dir="/" # convert to full path if [ "${file##/*}" ]; then file="${PWD}/${file}" fi # dir name of following dir next="${file#(编辑:4S站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐
- Linux / Unix Command: bunzip2--reference
- c – SIGXFSZ是由内核发送的,除非有什么内容打印
- c C 如何以编程方式获取linux中设备/分区的uuid?
- 如何在使用gcsfuse创建的Linux中卸载Google Buck
- 如何在没有find的情况下在linux shell脚本中根据
- linux – ssh multi-hop上的“bash:nc:command
- linux – 为什么`ls`每行列出多个文件,但`ls pip
- gedit插件错误 – 找不到插件加载器’python3′
- LINUX实战:Linux基础知识:网络属性配置
- linux – Bash“declare -A”在macOS上不起作用