Entries tagged reload

Crawling with Web Storage in PHP

Posted on 28. September 2019 Comments

Some pages have an extra screen before the real site appears, e.g. for age verification (like porn, for now anyways, or drug sites) or country/currency selection (like travel and big company sites). As far as I researched this, sometimes the selection is stored in a cookie, sometimes in Web Storage.

Crawling with Cookies is no problem with Guzzle.

But for example, at https://cannabis.wiki the age verification is stored in the Local Storage as you can see in the Chrome DevTools:

image

Using spatie/crawler we can inject a Browsershot (puppeteer) instance, that sets the localStorage key ageConfirmed through custom JavaScript:

$js = "localStorage.setItem('ageConfirmed', '1');";
$browsershot->setOption('addScriptTag', json_encode(['content' => $js]));

However, the code is only injected after the side is already loaded. Therefore we have to use JavaScript to reload the page:

$js = "localStorage.setItem('ageConfirmed', '1');location.reload()";
$browsershot->setOption('addScriptTag', json_encode(['content' => $js]));

You can test this on the console e.g. by using ->save($pathToFile); and have a look at the screenshot to see if it worked.

Midori Fullscreen und Reload im Sekundenintervall

Posted on 16. Oktober 2012 Comments

Ich wollte den Raspberry Pi benutzen, um auf einem großen Bildschirm eine Website mit Informationen darzustellen. Da doch hin und wieder mal die Internetverbindung verschwindet, war es mir wichtig einen Reload jede Stunde oder so zu haben. Bei Firefox könnte man jetzt ein Reload Plugin nehmen, der minimalistische Standard-Browser unter dem Debian Derivat RaspianMidori – unterstützt aber natürlich keine Plugins. Also habe ich ein kleines Skript geschrieben, welches in einer Endlosschleife ein sleep 3600 (3600 Sekunden = 1 Stunde) ausführt und dann mit dem Kommandozeilen-Parameter -e Reload einen Reload in dem schon geöffneten Midori macht. Außerdem möchte ich das Skript per SSH starten, also muss noch der Display :0 angegeben werden, s. Programme über SSH auf Display :0 starten. Für einen Fullscreen benutze ich schon beim ersten Start in Zeile 3 -e Fullscreen. Eine erste Idee, einfach einen Refresh über eine statische HTML Seite mit iframes zu machen, habe ich verworfen, weil es blöd aussah. Die Parameter -i <Sekunden> -a <Website> haben dazu geführt, dass oben die Adressleiste wieder sichtbar wurd.e. Weitere interessante Funktionen findet man mit midori –help-execute.

#!/bin/bash
export DISPLAY=:0
midori -e Fullscreen --display=:0 &
while [ TRUE ]; do
  sleep 3600
  midori -e Reload
done

Credits go to W. H. Heydt at raspberrypi.org Forum