Skip to content

Instantly share code, notes, and snippets.

@openm1ke
Last active September 20, 2021 10:35
Show Gist options
  • Select an option

  • Save openm1ke/9558ec7f8fd8e9e256c56efa3cadb27d to your computer and use it in GitHub Desktop.

Select an option

Save openm1ke/9558ec7f8fd8e9e256c56efa3cadb27d to your computer and use it in GitHub Desktop.
Top 30 tweets screensoter
<?php
//twitter screenshoter
require_once('vendor/autoload.php');
use Facebook\WebDriver\Remote\DesiredCapabilities;
use Facebook\WebDriver\Remote\RemoteWebDriver;
use Facebook\WebDriver\Chrome\ChromeOptions;
use Facebook\WebDriver\WebDriverBy;
use Facebook\WebDriver\WebDriverSelect;
use Facebook\WebDriver\WebDriverExpectedCondition;
use Symfony\Component\Process\Process;
use Mailtm\Mailtm;
$host = 'http://localhost:4444/wd/hub';
$options = new ChromeOptions();
$options->addArguments([
'no-sandbox',
'headless',
'window-size=1920,1080',
'start-maximized',
//'user-data-dir=/mnt/d/PhpScripts/selenium',
//'profile-directory=Profile 1',
'user-agent=Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36']);
$capabilities = DesiredCapabilities::chrome();
$capabilities->setCapability(ChromeOptions::CAPABILITY, $options);
$driver = RemoteWebDriver::create($host, $capabilities);
$driver->get('https://www.t30p.ru/microtop.aspx');
$element = $driver->findElements(WebDriverBy::xpath('//span[@class="a"]/a[@class="title"][1]'));
foreach ($element as $el) {
$tweet_url[] = $el->getAttribute("href");
}
foreach($tweet_url as $k=>$url) {
echo $k." - ".$url."\r\n";
$driver->get($url);
$driver->wait()->until(WebDriverExpectedCondition::visibilityOfElementLocated(WebDriverBy::tagName("article")));
$element = $driver->findElement(WebDriverBy::tagName("article"));
$element->takeElementScreenshot($k.'-tweet-screenshot.png');
}
$driver->quit();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment