Answer the question
In order to leave comments, you need to log in
How to replace the truncated image size with an adequate one?
I work with aliexpress, I need to parse the picture, the problem arose, for some reason the size is 220x220, although the original is much larger, please tell me where to correct it?
$links = [];
$doc = phpQuery::newDocument($content);
foreach(pq('li.list-item') as $li) {
$el = pq($li);
$link = [];
$link['url'] = 'http:' . $el->find('a.product')->attr('href') . PHP_EOL;
$link['img'] = '';
$im_el = pq($el->find('img.picCore'));
if( $im_el->attr('src') ) {
$link['img'] = 'http:' . $im_el->attr('src');
}elseif( $im_el->attr('image-src') ) {
$link['img'] = 'http:' . $im_el->attr('image-src');
}else continue;
$link['text'] = $el->find('a.product')->text();
$link['id'] = $el->find('a.atwl-button')->attr('data-product-id');
$links []= $link;
}
Answer the question
In order to leave comments, you need to log in
There are no links to large images on the product listing page, only thumbnails, so you can't find the link. But you can replace 220x220 in links with 640x640, it seems to work
foreach(pq('li.list-item') as $li) {
$el = pq($li);
$link = [];
$link['url'] = 'http:' . $el->find('a.product')->attr('href') . PHP_EOL;
$link['img'] = '';
$im_el = pq($el->find('img.picCore'));
if( $im_el->attr('src') ) {
$link['img'] = 'http:' . $im_el->attr('src');
}elseif( $im_el->attr('image-src') ) {
$link['img'] = 'http:' . $im_el->attr('image-src');
}else continue;
$link['text'] = $el->find('a.product')->text();
$link['id'] = $el->find('a.atwl-button')->attr('data-product-id');
$links []= $link;
}
foreach( $links as $link ) {
if( mb_strpos($done, $link['id'] . '-') !== FALSE ) {
echo $link['id'] . ' already done' . PHP_EOL;
continue;
}
if( $post = createPost($link) ) {
echo 'Post #' . $post . ' Created' . PHP_EOL;
file_put_contents(__DIR__ . '/complete.links', $link['id'] . '-' . PHP_EOL, FILE_APPEND);
break;
}
}
function createPost( $link ) {
global $settings;
$img = file_put_contents('photo.jpg', file_get_contents($link['img']));
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question