Answer the question
In order to leave comments, you need to log in
How to save the result of parsing in MySQL.?
Good afternoon. I got a test task for php-jun: Using
the “Download” button, parse the last 5 articles from the site https://habr.com and save to
the database. After parsing is completed, display the received articles on the pages.
2. On the same page, display a list of articles received earlier. Display 5 articles
per page. Add a paginator to navigate through pages.
3. The link from the title of the article should open an article on the site
https://habr.com in a new browser tab. The text of articles on the page should be displayed truncated to 200 characters.
The “Full text” button should display the full content of the article in the modal window
in full screen. The modal window should have a cross that closes it.
4. Updating the list of articles after parsing, turning pages and displaying the full content of the
article should occur without reloading the page.
I decided to use the DiDom library, because. I have no experience, all that I have figured out at the moment is this:
require_once('vendor/autoload.php');
use DiDom\Document;
$document = new Document('https://habr.com/ru/all/', true);
$posts = $document->find('.post');
$last5posts = array_slice($posts, 0, 5);
foreach($last5posts as $post) {
echo $post->html(), "\n";
}
Answer the question
In order to leave comments, you need to log in
If it's quite simple, then save the html to the text and just save it to the database with the PK ID, and then display it on the page with ajax using this id. Modal is also js, you can use some jQuery, for the same simplicity. Pagination is also js, it is easy to google, for beauty you can use some datatable.
I have no idea what DiDom is :)
I almost choked on such a task ...
Some drug addict came up with it.
DON'T GO TO THEM TO WORK, you hear? They are idiots.
And their assignments are extremely idiotic.
Figuratively I imagine what should happen, but how to implement it is not very clearMe too. Idiot tasks are generally very difficult to analyze.
create a table in the database, where the key field is the ID of the article, the second field is the title of the article, the third is the text of the article, etc.
then from the table it will be easy to select info on 5 records with LIMIT 5
I would recommend using phpQuery to define the selectors and write to the RedBeanPHP ORM database. and if you want a finished one, you can see the article here https://obninsksite.ru/blog/php-scripts/parser-na-...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question