7
$\begingroup$

I am trying to load player profile pictures from the following page:

https://www.transfermarkt.com/manchester-united/startseite/verein/985/saison_id/2006#

I use the following code:

Import["https://www.transfermarkt.com/manchester-united/startseite/\
verein/985/saison_id/2006#", "Images"]

Unfortunately, all profile images are loaded as follows: enter image description here

All images I do not need are in the correct format...

The pause function (e.g., for one second)

Pause[1]

only works between tasks. So I do not think I can use it.

Any ideas how to solve this issue?

$\endgroup$
10
$\begingroup$

If you write an HTML img tag like this:

<img src="url/to/image.jpg">

then the image will be downloaded directly upon page load. Some frontend developers don't like this as they think it's more important to quickly show the bulk of the page. The images can come later. So what they did in this case was writing

<img data-src="url/to/image.jpg">

They then use JavaScript to get the URLs from the data-src attributes and load the images that way. Clearly, this is not something that Import can figure out. However, using this knowledge, we can do it quite easily with jsoupLink:

<< jsoupLink`

html = Import[
   "https://www.transfermarkt.com/manchester-united/startseite/verein/985/saison_id/2006#",
   "HTMLDOM"
   ];
images = html["Select", ".bilderrahmen-fixed"];
images = Import[#["Attribute", "data-src"]] & /@ images;
Partition[images, 8] // Grid

Mathematica graphics

$\endgroup$
  • $\begingroup$ Perfect, thanks a lot! $\endgroup$ – Philippe Dufour Aug 28 at 18:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.