我需要一些帮助,因为我编写了一个使用这个优秀API的PHP类: http://it-ebooks-api.info并且效果很好。从我的表单中,您可以放置一个像PHP,Jquery等的参数,你将获得所有前10本书的结果,最后我使用Select来让用户查看其余所有书籍。结果/书籍。
现在我注意到只有原始API网站允许您直接下载图书。 我猜他们会使用一些JavaScript代码以及一段时间后发生故障的会话,以防止他们的免费API用户直接下载您可能需要的图书。
如果您点击下载链接,您将最终进入另一页,其中包含您必须履行的验证码书的详细信息! 完成后,下载终于开始了!
是否有可能避免这种情况,并且有可能直接下载我需要的书,而不会在那个恼人的验证码上登陆该死的页面?
这是一个免费的API,但这种行为超出了自由:你必须接受去那个页面,以正确的方式执行验证码(当然),只有这样,感谢他们或为了上帝的缘故,你'允许下载您选择的书。
这种态度让我很生气,因为我不喜欢这样一个虚假的免费API,但我仍然在网上搜索,但我没有更好的。
我非常感谢有所帮助。
这是我的课程,我称之为 EbooksSearchDownload 。
<?php
class EbooksSearchDownload
{
// Error code / description (Note: request success code = 0)
public $Error;
// Request query execution time (seconds)
public $Time;
// Array which contains all details of the books
public $books;
// The total number of books found
public $total;
// The total number of pages/results (Note: limit = 10 books per page)
public $pages;
public function __construct($ebook, $page)
{
/**
* See here for info about this API: http://it-ebooks-api.info/
* First the book search, this way:
* http://it-ebooks-api.info/v1/search/{QUERY}/page/{NUMBER}
*/
$response = $this->fetch("http://it-ebooks-api.info/v1/search/{$ebook}/page/{$page}");
// decode the JSON into an associative array, setting the option to true
$data = json_decode($response, true);
# This will print out the contents of the array in a nice readable format
# echo '<pre>' . print_r($data, true) . '</pre>';
$this->total = $data['Total'];
/**
* HOW TO GET THE TOTAL NUMBER OF PAGES:
*
* As the API shows only 10 books per page, if I want to know how many pages contain
* all books (here the property, $total), I have to pass thru three different steps:
*
* 1) I divide the total number of the books by 10: e.g. 141/10 gives 14,1
*
* 2) then I use the function intval() to get the integer value stripping the
* the decimal part: e.g. 14
*
* 3) then, if there is a remainder from the division, I get it with the modulus
* operator % and I add one more page to obtain the number of the total pages:
* e.g. here the 1 and in this case, I've got 141 books on 15 pages.
*/
$this->pages = intval($data['Total']/10) + ($data['Total']%10 ? 1 : 0);
// Extract all details about the books
// Here I use 'Books' as the key to the array to get all info.
// 'Books' and 'ID' come from the API above.
for ( $i = 0; $i < count($data['Books']); $i++ )
{
/**
* Then the download and other info of the chosen book, this way:
* http://it-ebooks-api.info/v1/book/{ID}
*/
$response = $this->fetch("http://it-ebooks-api.info/v1/book/{$data['Books'][$i]['ID']}");
$this->books[] = json_decode($response, true);
}
}
public function fetch($host)
{
if ( function_exists('curl_init') )
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $host);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
curl_close($ch);
}
else if ( ini_get('allow_url_fopen') )
{
$response = file_get_contents($host, 'r');
}
return $response;
}
}
以下是我如何使用它(我省略了头部和身体标签):
<?php
error_reporting(E_ALL ^ E_NOTICE);
require_once 'settings_ebook.php';
require_once 'EbooksSearchDownload.class.php';
echo "
<h1 class='centra sottolineato grassetto rosso'>Cerca un argomento e scarica un ebook</h1>
<form action='ebook.php' method='get' id='ebookForm'>
<fieldset>
<legend class='centra'>Inserisci un argomento e cerca un ebook</legend>
<ol>
<li>
<label for='ebook'>Ebook<abbr title='campo obbligatorio'>*</abbr></label>
<input type='text' name='ebook' id='ebook' value='" . ( isset($_GET['ebook']) && ! empty($_GET['ebook']) ? strip_tags(trim($_GET['ebook'])) : '' ) . "' class='" . ( isset($_GET['ebook']) && empty($_GET['ebook']) ? 'error' : '' ) . "' />
</li>
</ol>
</fieldset>
<p class='controls'>
<input type='submit' value='Invia' />
</p>
</form>";
if ( isset($_GET['ebook']) && ! empty($_GET['ebook']) )
{
$_GET['page'] = isset($_GET['page']) ? $_GET['page'] : 1;
$eb = new EbooksSearchDownload($_GET['ebook'], $_GET['page']);
/**
* Check for the results!
*
*/
if ( is_array($eb->books) )
{
echo "Totale libri: " . $eb->total . " - Pagina {$_GET['page']} di " . $eb->pages . "<br /><br /><hr class='style-eight'></hr>";
foreach ( $eb->books as $book )
{
// the first 10 books:
echo '<p>' .
// 'Error code: ' . $book['Error'] . '<br />' .
// 'Request query execution time: ' . $book['Time'] . '<br /></p>' .
'Tempo esecuzione della query: ' . $book['Time'] . '<br /></p>' .
'<p class="grassetto">' . 'ID ebook: ' . '</p>' .
'<p>' . $book['ID'] . '</p>' .
'<p class="grassetto rosso sottolineato">' . 'Titolo: ' . '</p>' .
'<p class="rosso">' . $book['Title'] . '</p>' .
'<p class="grassetto" >' . 'Sottotitolo: ' . '</p>' .
'<p>' . $book['SubTitle'] . '</p>' .
'<p class="grassetto">' . 'Descrizione: ' . '</p>' .
'<p>' . $book['Description'] . '<br /></p>' .
'<p class="grassetto rosso sottolineato">' . 'Autore: ' . '</p>' .
'<p class="rosso">' . $book['Author'] . '<br /></p>' .
'<p class="grassetto">' . 'ISBN: ' . '</p>' .
'<p>' . $book['ISBN'] . '<br /></p>' .
'<p class="grassetto">' . 'Anno: ' . '</p>' .
'<p>' . $book['Year'] . '<br /></p>' .
'<p class="grassetto">' . 'Pagine: ' . '</p>' .
'<p>' . $book['Page'] . '<br /></p>' .
'<p class="grassetto rosso sottolineato">' . 'Casa Editrice: ' . '</p>' .
'<p class="rosso">' . $book['Publisher'] . '<br /></p>' .
'<p><img src="' . $book['Image'] . '" alt="" />' . '</p>' .
'<p><a href="' . $book['Download'] . '" target="_blank">' . 'scarica' . '</a>' . '<br /></p><hr class="style-eight"></hr>';
}
echo "
<form action='ebook.php' method='get'>
Pagina
<select name='page' onchange='this.form.submit()'>";
for ( $i = 1; $i <= $eb->pages; $i++ )
{
echo "
<option value='{$i}'" . ( $i == $_GET['page'] ? " selected='selected'" : "" ) . ">{$i}</option>";
}
echo "
</select>
<input type='hidden' name='ebook' value='{$_GET['ebook']}' />
</form>";
// show a message for the correct data
$info_message = '<p class="info">' . $ebook_existing . '</p>';
}
}
/* ERRORS TO BE PRINTED ON THE SCREEN */
// if not all required fields have been filled
if ( isset($_GET['ebook']) && empty($_GET['ebook']) )
$info_message = '<p class="error">' . $error_missing_field . '</p>';
// if the ebook doesn't exist
else if ( isset($_GET['ebook']) && ! empty($_GET['ebook']) && ! is_array($eb->books) )
$info_message = '<p class="error">' . $ebook_unexisting . '</p>';
// Show both a confirm message and an error message
if ( isset( $info_message) && strlen($info_message) )
echo $info_message;
?>
这是我的网站(意大利语),它使用上述API。 if you wanna have a look:
感谢。
答案 0 :(得分:-1)
这不是一个错误,它是一个功能。
大概出于安全原因,要防止(D)DOS攻击和/或出于许可原因以防止大量下载。
但是如果你感到幸运的话:带有下载URL的书
http://filepi.com/i/qqkNNW2
可以实际下载(进入验证码后)
http://cdn2.filepi.com/g/qqkNNW2/1446376978/4a79bb1807795fdec1313e97bfd43d1b
遵循以下模式:
http://cdn2.filepi.com/[g instead of i]/[book id]/[current timestamp]/[md5 hash]
如果哈希是通过简单的东西生成的,那么这个拼图可能是可以破解的。 所以根据你的想法逆向工程:祝你好运!