1
$\begingroup$

I have this code that shows many hyperlinks

links = Import[
"http://www.liceobrainstorm.cl/wp-content/uploads/2020/07/", 
"Hyperlinks"]

Unfortunately some of them appear with the % symbol, I don't know why).

the idea is that once the list is obtained I can interact with it and show me only those that meet a criterion, for example for this example all those that say "MEDIO-B", but if you can download them in a particular directory it would be great.

$\endgroup$
4
  • 1
    $\begingroup$ Your code works fine. The %c2%b0 you see in links is mostly because of ° in file names. For filtering names, you could use Select[links, StringContainsQ[#, "MEDIO-B", IgnoreCase -> True] &] $\endgroup$
    – Ben Izd
    May 3, 2021 at 18:15
  • 2
    $\begingroup$ Those are encoded URL's, use URLDecode. links = Import["http://www.liceobrainstorm.cl/wp-content/uploads/2020/07/", "Hyperlinks"] // Map[URLDecode] $\endgroup$ May 3, 2021 at 18:42
  • 2
    $\begingroup$ To download Select[links, StringContainsQ[#, "MEDIO-B", IgnoreCase -> True] &] // URLDownload[#, "~/Downloads"] &;. Replace MEDIO-8 with whatever string you want to search for, replace ~/Downloads with the name of the directory to download the files to. $\endgroup$ May 3, 2021 at 18:53
  • $\begingroup$ @Rohit Namjoshi hi , thanks ,I'm trying to make it work like this, I'm also trying to ask for the directory, what am I doing wrong? url = Input ["enter url"] links = Import[url, "Hyperlinks"] // Map[URLDecode]; text = Input["enter text to download"] (Select[links,StringContainsQ[#,"Matem",IgnoreCase[Rule]True]&]) Select[links, StringContainsQ[#, text, IgnoreCase -> True] &] // URLDownload[#, "D:\\zmios"] &; I need the same to choose the previously created directory $\endgroup$
    – BeTDa
    May 4, 2021 at 17:20

1 Answer 1

2
$\begingroup$

Update Download for all months

(* e.g. http://www.liceobrainstorm.cl/wp-content/uploads/2020/ *)   
url = InputString["enter url"]; 

(* e.g. Matem *)
text = InputString["enter text to download"];

(* Choose directory for downloaded files *)
dir = SystemDialogInput["Directory", $HomeDirectory];

months = IntegerString[#, 10, 2] & /@ Range[12];

links = months // Map[Import[url <> # <> "/", "Hyperlinks"] &] // Flatten // Map[URLDecode];

selectedLinks = Select[links, StringContainsQ[#, text, IgnoreCase -> True] &]

If[FreeQ[dir, $Canceled], selectedLinks // URLDownload[#, dir] &, Print["Cancelled"]]

url = InputString["enter url"];

links = Import[url, "Hyperlinks"] // Map[URLDecode];

text = InputString["enter text to download"];

selectedLinks = Select[links, StringContainsQ[#, text, IgnoreCase -> True] &];

dir = SystemDialogInput["Directory", $HomeDirectory]

If[FreeQ[dir, $Canceled], selectedLinks // URLDownload[#, dir] &, Print["Cancelled"]]
$\endgroup$
1
  • $\begingroup$ Comments are not for extended discussion; this conversation has been moved to chat. $\endgroup$
    – Kuba
    May 8, 2021 at 4:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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