Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


How to browse a web page periodically and check for certain sting
New on LowEndTalk? Please Register and read our Community Rules.

All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.

How to browse a web page periodically and check for certain sting

I want to monitor a web page or multiple ones for a certain keyword present in HTML. Actually I am doing this for a friend as she wants to order one item from a clothing website and it remains out of stock most of the time.
So, I want to make her a service/cron job that will monitor if the stock is available and send her alert.
I know I can do this in PHP using file_get_contents but I was thinking if there is a better way to do it as the site may ban me if I check it very often and I think it cannot emulate browser very good. Or may be we can emulate browser using file_get_contents.
Suggest me some better way. May be some browser library I can use in PHP that will open that page and read HTML?

Comments

  • EthernetServersEthernetServers Member, Patron Provider

    Nodeping has this functionality, if you're willing to pay: https://nodeping.com/http_content_check.html

    Or you can just check out that link to learn more about how it works, and then build your own version.

    Thanked by 1alilet
  • Hi ! I am using this opensource project that you can selfhost

    https://github.com/dgtlmoon/changedetection.io

    Thanked by 1alilet
  • I went ahead and wrote the following very simple script. It checks for certain string in web page and is running fine for the past 3 days. As soon as that string is found, it will send WhatsApp message to her.

    This is not complete code but just initial part of it which calls web page.

    $url = "https://www.example.com";
    
    $context = stream_context_create(
            array(
                "http" => array(
                    'method'=>"GET",
                    "header" => "User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) 
                                AppleWebKit/537.36 (KHTML, like Gecko) 
                                Chrome/50.0.2661.102 Safari/537.36\r\n" .
                                "accept: text/html,application/xhtml+xml,application/xml;q=0.9,
                                image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3\r\n" .
                                "accept-language: es-US,us;q=0.9,en;q=0.8,it;q=0.7\r\n"
                )
            )
        );
    
    $f = file_get_contents($url, false, $context);
    
    Thanked by 1plumberg
  • Ask chatgpt :)

    Thanked by 1neverain
  • instavpsinstavps Member, Patron Provider

    I use visual ping free version, seems to work.

Sign In or Register to comment.