• 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

    • Nope. This will be disabled instantly on all my devices. But at least they're not forcing it upon users, it can be turned off.
    • But, but, Meta did not have address to your data? I don’t believe this cap. Why-o-why don’t I trust them?!
    • They're not lying in this case, violating your privacy and safety is certainly of utmost importance to Zuck and his creeps...
    • Microsoft employee behind AnduinOS releases more updates, here's how to upgrade by Paul Hill A small Linux distribution created by a Microsoft employee drew quite a bit of attention in recent months with its attempts to ease users into Linux by looking just like Windows. This week, AnduinOS was upgraded to a new batch of point releases, including 1.3.3, 1.2.6, and 1.1.6. These point releases do not bring too many changes, and all the changes that are introduced are identical across all three versions. Here are the release notes this time: Fixed an accessibility issue that caused the screen reader unable to read the text. Added librime-plugin-lua for ibus-rime users to support Lua scripts. This only affects zh_CN by default. Added policykit-desktop-privileges to the default app list to allow no-password prompts for mount, simple updates, etc. As a new Linux distribution on the scene, updating it is not as straightforward as opening a software store and tapping the upgrade button. For now, upgrades rely on a script. To update your computer using this script, open up a terminal window and type do_anduinos_upgrade. Running this command will bring you up to the latest point release for your respective major version, even if you’re not on the latest point release right now. In the future, Anduin Xue, the Microsoft employee who develops AnduinOS, wants to allow you to grab new versions via sudo apt upgrade. For the time being, users will need to stick to running the script to ensure their device is up to date. Last month, it was announced that AnduinOS 1.4 will be based on Ubuntu 25.10 and will drop in late October, while Anduin OS 1.5 will be based on Ubuntu 26.04 LTS and arrive in late April 2026. Hopefully, we will see more maturation with those updates, such as upgrading the system with an apt command instead of a script.
    • I know companies like to assume first party ads are okay, and I often don't have a huge problem with things like extra iCloud space offers showing up in relevant places. Relevant being the keyword. There is literally nowhere on a phone where a movie ad would ever be in context.
  • Recent Achievements

    • First Post
      solidox earned a badge
      First Post
    • First Post
      BA the Curmudgeon earned a badge
      First Post
    • One Year In
      blissa jayden earned a badge
      One Year In
    • One Month Later
      blissa jayden earned a badge
      One Month Later
    • Week One Done
      blissa jayden earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      561
    2. 2
      ATLien_0
      213
    3. 3
      +FloatingFatMan
      171
    4. 4
      Michael Scrip
      152
    5. 5
      Som
      151
  • Tell a friend

    Love Neowin? Tell a friend!