A
A
AdaSchwartz2018-02-27 12:23:21
PHP
AdaSchwartz, 2018-02-27 12:23:21

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

2 answer(s)
I
imhuman, 2018-02-27
@imhuman

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

A
AdaSchwartz, 2018-02-27
@AdaSchwartz

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 question

Ask a Question

731 491 924 answers to any question