Skip to main content
added 50 characters in body
Source Link
chuy
  • 399
  • 1
  • 5

Wolfram Language/Mathematica, 118118 117 bytes

saved a byte thanks to numbermanic

If[ImportString[#,"HTML"]===#,#,$Failed]&@Import[StringTemplate["http://xkcd.com/``/info.0.json"]@#,"RawJSON"]["alt"]&"RawJSON"]@"alt"&

Explanation:

Use StringTemplateto form the URL from the input.

Import[..., "RawJSON"] imports the JSON object and parses it into an Assocation.

Select the value for the key "alt".

Take this result and try to interpret the string as HTML (Import[#,"HTML"]). If this doesn't change anything pass the result through, if it does return $Failed. This catches 859 because

ImportString[
 "Brains aside, I wonder how many poorly-written xkcd.com-parsing 
  scripts will break on this title (or ;;\"''{<<[' this mouseover text.\"","HTML"]

results in:

Brains aside, I wonder how many poorly-written xkcd.com-parsing 
scripts will break on this title (or ;;"''{

404 fails because

If[
 ImportString[$Failed["alt"], "HTML"] === $Failed["alt"], 
 $Failed["alt"],
 $Failed]

results in $Failed.

Wolfram Language/Mathematica, 118 bytes

If[ImportString[#,"HTML"]===#,#,$Failed]&@Import[StringTemplate["http://xkcd.com/``/info.0.json"]@#,"RawJSON"]["alt"]&

Explanation:

Use StringTemplateto form the URL from the input.

Import[..., "RawJSON"] imports the JSON object and parses it into an Assocation.

Select the value for the key "alt".

Take this result and try to interpret the string as HTML (Import[#,"HTML"]). If this doesn't change anything pass the result through, if it does return $Failed. This catches 859 because

ImportString[
 "Brains aside, I wonder how many poorly-written xkcd.com-parsing 
  scripts will break on this title (or ;;\"''{<<[' this mouseover text.\"","HTML"]

results in:

Brains aside, I wonder how many poorly-written xkcd.com-parsing 
scripts will break on this title (or ;;"''{

404 fails because

If[
 ImportString[$Failed["alt"], "HTML"] === $Failed["alt"], 
 $Failed["alt"],
 $Failed]

results in $Failed.

Wolfram Language/Mathematica, 118 117 bytes

saved a byte thanks to numbermanic

If[ImportString[#,"HTML"]===#,#,$Failed]&@Import[StringTemplate["http://xkcd.com/``/info.0.json"]@#,"RawJSON"]@"alt"&

Explanation:

Use StringTemplateto form the URL from the input.

Import[..., "RawJSON"] imports the JSON object and parses it into an Assocation.

Select the value for the key "alt".

Take this result and try to interpret the string as HTML (Import[#,"HTML"]). If this doesn't change anything pass the result through, if it does return $Failed. This catches 859 because

ImportString[
 "Brains aside, I wonder how many poorly-written xkcd.com-parsing 
  scripts will break on this title (or ;;\"''{<<[' this mouseover text.\"","HTML"]

results in:

Brains aside, I wonder how many poorly-written xkcd.com-parsing 
scripts will break on this title (or ;;"''{

404 fails because

If[
 ImportString[$Failed["alt"], "HTML"] === $Failed["alt"], 
 $Failed["alt"],
 $Failed]

results in $Failed.

Added more explanation
Source Link
chuy
  • 399
  • 1
  • 5

Wolfram Language/Mathematica, 118 bytes

If[ImportString[#,"HTML"]===#,#,$Failed]&@Import[StringTemplate["http://xkcd.com/``/info.0.json"]@#,"RawJSON"]["alt"]&

Explanation:

Use StringTemplateto form the URL from the input.

Import[..., "RawJSON"] imports the JSON object and parses it into an Assocation.

Select the value for the key "alt".

Take this result and try to interpret the string as HTML (Import[#,"HTML"]). If this doesn't change anything pass the result through, if it does return $Failed. This catches 859 because

ImportString[
 "Brains aside, I wonder how many poorly-written xkcd.com-parsing 
  scripts will break on this title (or ;;\"''{<<[' this mouseover text.\"","HTML"]

results in:

Brains aside, I wonder how many poorly-written xkcd.com-parsing 
scripts will break on this title (or ;;"''{

404 fails because

If[
 ImportString[$Failed["alt"], "HTML"] === $Failed["alt"], 
 $Failed["alt"],
 $Failed]

results in $Failed.

Wolfram Language/Mathematica, 118 bytes

If[ImportString[#,"HTML"]===#,#,$Failed]&@Import[StringTemplate["http://xkcd.com/``/info.0.json"]@#,"RawJSON"]["alt"]&

Wolfram Language/Mathematica, 118 bytes

If[ImportString[#,"HTML"]===#,#,$Failed]&@Import[StringTemplate["http://xkcd.com/``/info.0.json"]@#,"RawJSON"]["alt"]&

Explanation:

Use StringTemplateto form the URL from the input.

Import[..., "RawJSON"] imports the JSON object and parses it into an Assocation.

Select the value for the key "alt".

Take this result and try to interpret the string as HTML (Import[#,"HTML"]). If this doesn't change anything pass the result through, if it does return $Failed. This catches 859 because

ImportString[
 "Brains aside, I wonder how many poorly-written xkcd.com-parsing 
  scripts will break on this title (or ;;\"''{<<[' this mouseover text.\"","HTML"]

results in:

Brains aside, I wonder how many poorly-written xkcd.com-parsing 
scripts will break on this title (or ;;"''{

404 fails because

If[
 ImportString[$Failed["alt"], "HTML"] === $Failed["alt"], 
 $Failed["alt"],
 $Failed]

results in $Failed.

Source Link
chuy
  • 399
  • 1
  • 5

Wolfram Language/Mathematica, 118 bytes

If[ImportString[#,"HTML"]===#,#,$Failed]&@Import[StringTemplate["http://xkcd.com/``/info.0.json"]@#,"RawJSON"]["alt"]&