HDI:在 bash 中检查网站上商品的“库存”状态?

问题描述 投票:0回答:2

我在网站上查找库存商品时遇到了麻烦。 我一直错过它大约半小时左右。

如何提取尼康商店页面的内容 ( http://shop.nikonusa.com/store/nikonusa/en_US/pd/productID.249538300 ) 并向自己发送电子邮件提醒 ([email protected] )当灰色的“哪里购买”按钮已替换为黄色的“立即购买”按钮时(可以在此处看到:http://shop.nikonusa.com/store/nikonusa/en_US/pd/productID.226487200 )。 这可以通过 bash 脚本实现吗?还是太复杂了?

谢谢!

bash web-scraping webstore
2个回答
1
投票

您可以使用 curl 抓取网页,然后使用 grep 搜索按钮的替代文本...

#!/bin/bash
#D800
x=$( curl -s http://shop.nikonusa.com/store/nikonusa/en_US/pd/productID.249538300 | grep 'alt="Buy Now"')
#D7000 (for testing)
#x=$( curl -s http://shop.nikonusa.com/store/nikonusa/en_US/pd/productID.226487200 | grep 'alt="Buy Now"')
if [ ! -n "$x" ]
then
    echo Not Available
    exit 1
fi
echo "Get clicking" | mail -s "D800 Available" [email protected]

0
投票

我最终和 wget 一起丑化了一些东西。

如果有人遇到同样的问题,半清理代码如下:

#!/bin/bash
while [ ! -f mailready ]
do
sleep 450
echo -e "\n Trying wget [URLHERE]"
wget -N [URLHERE]
        if grep -q buy-now [Downloaded URLfile]
        then
                echo -e "\n Buy now button found at [URL, DATE]\" > scriptbuffer
                cat mailheader scriptbuffer > mailready
                cat mailready| msmtp [email protected]
                echo -e "\nBuy-now button found... ending"
        else
                echo -e "\nNo Buy-now button found"
        fi
done

它对我来说非常有效,我不知道自己到底在做什么。 我设置它大约每 7 分钟检查一次,两三个小时后,我就可以下订单了。

© www.soinside.com 2019 - 2024. All rights reserved.