• 0

Good way to list the contents of a dropbox folder in php


Question

4 answers to this question

Recommended Posts

  • 0

This is the scraper that I have so far:


<?php

// Get drobox folder html.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://www.dropbox.com/sh/mneh7sehw63cvk6/VcWEokE4yH' ); // Dropbox shared folder link
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3 (FM Scene 4.6.1)');
curl_setopt($ch, CURLOPT_REFERER, 'https://www.dropbox.com/');
curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate');
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
$html =curl_exec ($ch);
// extract links with DOMDocument
$dom = new DOMDocument();
@$dom->loadHTML($html);
$links = $dom->getElementsByTagName('a');
$processed_links = array();
foreach ($links as $link)
{
if ($link->hasAttribute('class')&& $link->hasAttribute('href'))
{
foreach ($link->attributes as $a)
{
if ($a->value=='filename-link')
{
$processed_links[$link->getAttribute('href')] = $link->getAttribute('href');
}

}

}
}


echo var_dump($processed_links);




?>
[/CODE]

  • 0

Why are you scraping a webpage when Dropbox have an API?

edit; sorry, my mistake, after looking through the Dropbox API for some reason it seems like they have a call to access shared/public folders. :huh:

  • 0
  On 22/03/2013 at 18:18, ZakO said:

Why are you scraping a webpage when Dropbox have an API?

edit; sorry, my mistake, after looking through the Dropbox API for some reason it seems like they have a call to access shared/public folders. :huh:

I found it's odd that they don't allow to simply list a directory like this without OAuth.

I managed to put together something with the scraper to get all images and txt files and display them. Seems to work ok :


<?php

// Get drobox folder html.
$folder = 'https://www.dropbox.com/sh/mneh7sehw63cvk6/VcWEokE4yH'; // Dropbox shared folder link
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $folder);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3 (FM Scene 4.6.1)');
curl_setopt($ch, CURLOPT_REFERER, 'https://www.dropbox.com/');
curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate');
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
$html =curl_exec ($ch);
// extract links with DOMDocument
$dom = new DOMDocument();
@$dom->loadHTML($html);
$links = $dom->getElementsByTagName('a');
$processed_links = array();
foreach ($links as $link)
{
if ($link->hasAttribute('class')&& $link->hasAttribute('href'))
{
foreach ($link->attributes as $a)
{
if ($a->value=='filename-link')
{
$processed_links[$link->getAttribute('href')] = $link->getAttribute('href');
}

}

}
}

$exts = $processed_links;
foreach ($exts as $ext)
{
$url = $ext;

$path = parse_url($url, PHP_URL_PATH);

$ext2 = pathinfo($path, PATHINFO_EXTENSION);

// echo "<br> <a href=https://dl.dropbox.com$path>http://dl.dropbox.com$path</a

if ($ext2 == 'jpg')
{
echo "<br> <a href=https://dl.dropbox.com$path><imghhttps://dl.dropbox.com$path></img></a
//echo $path;
}
if ($ext2 == 'txt')
{
$first = "https://dl.dropbox.com";

$ch2 = curl_init();
curl_setopt($ch2, CURLOPT_URL, $first.$path); // textfile
curl_setopt($ch2, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3 (FM Scene 4.6.1)');
curl_setopt($ch2, CURLOPT_REFERER, 'https://www.dropbox.com/');
curl_setopt($ch2, CURLOPT_ENCODING, 'gzip,deflate');
curl_setopt($ch2, CURLOPT_AUTOREFERER, true);
curl_setopt($ch2, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch2, CURLOPT_TIMEOUT, 5);
curl_setopt($ch2, CURLOPT_RETURNTRANSFER, 1);
$str =curl_exec ($ch2);
//echo preg_replace('!\r?\n!', '<br>', $str);
echo '<pre>';
echo preg_replace('!\r?\n!', '<br>', $str);
echo '</pre>';
}
}

?>
[/CODE]

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • Elden Ring Nightreign will finally gain ‘Duo Expeditions' next week by Pulasthi Ariyasinghe FromSoftware's latest project, Elden Ring Nightreign, delivered a multiplayer-focused experience for the first time. While the title offered solo runs as an alternative to its standard three-player Trio Expeditions, Duos were surprisingly missing at launch. A couple of months later, the developer is finally delivering this highly requested feature for the hit roguelike. On social media, the studio confirmed that Duo Expeditions will be hitting Elden Ring Nightreign with the next update, patch 1.02, for the game on July 30. Check out the newly released trailer showing off this mode below. As we mentioned in our review of Elden Ring Nightreign, everything from enemy health, boss aggression, player damage, and even XP gain changes depending on how many players are in the Expedition. A post-launch update even tweaked the difficulty to favor solos as well. Duos should have the same changes being applied, with the mode being easier than trios but harder than solos to complete. Making sure the difficulty is properly balanced has previously been given as the reason why the Duos mode has taken a while to come in. FromSoftware also confirmed that patch 1.02 will have a range of more quality-of-life improvements on the UI side. This will include more Relics filtering options, making custom builds easier to construct before going on new runs, as seen below. Publisher Bandai Namco also announced this week that the Elden Ring Shadow of the Erdtree expansion for the original open-world Soulslike recently passed 10 million players. Meanwhile, this Elden Ring Nightreign spin-off now has over 5 million players, making both massive successes for the publisher. While FromSoftware is now focusing on other projects, Bandai Namco isn't done with the Elden Ring universe just yet either, as a live-action movie has now been confirmed to be in development too.
    • Or you ignore the part where @Michael Scrip answered you directly.
    • The reasons for Microsoft being in near perpetual state of reorganization for two years is due to the 6 CapEx acquisitions between Jan 2022 and Jan 2023, Blizzard, Oribi, Minit, Miburo, Lumenisity and Fungible. There were 15 CapEx acquisitions in 2021 alone. Much like the Borg, Microsoft assimilates knowledge instead of expending resources on learning and development. 10 gaming companies, 3 AI and 1 data modeling companies since 2018. But then this is in the founding DNA of Microsoft, MS DOS wasn't made by MS, Windows was based on the Apple Mac and Xerox PARC Alto....and on and on. (To be fair Apple's Lisa and Mac were from the Alto also)
    • Can't get a pic of the physical server as it's in a DC, but what i'm running on it is doable. All for my own use except one VM used by a friend to run her site and other things.
    • Immediately using a VPN that makes me appear to be in the EU.
  • Recent Achievements

    • Very Popular
      d4l3d earned a badge
      Very Popular
    • Dedicated
      Stephen Leibowitz earned a badge
      Dedicated
    • Dedicated
      Snake Doc earned a badge
      Dedicated
    • One Month Later
      Philsl earned a badge
      One Month Later
    • One Month Later
      armandointerior640 earned a badge
      One Month Later
  • Popular Contributors

    1. 1
      +primortal
      629
    2. 2
      ATLien_0
      238
    3. 3
      Xenon
      163
    4. 4
      neufuse
      123
    5. 5
      +FloatingFatMan
      123
  • Tell a friend

    Love Neowin? Tell a friend!