Hot answers tagged

39

Warning This answer pertains to the original release of jsoupLink. The interface changed completely in a later version. Please see the Github page for the current interface. ================================= As much as I would like to see a solution to this problem written in Mathematica, this is very unlikely given the scope of the problem. I would like ...


13

Since the Google Translate API requires authentication, a simple work around is to deploy as a web app a Google Apps Script that uses Google's LanguageApp, and then call that using URLExecute[]. To setup the Apps Script, go to script.google.com and create a new script with the following doGet function that uses the LanguageApp.translate method: function ...


13

Update 10-2017: I noticed that they released an update of these tools, so some of these steps are outdated. I adjusted this answer to the newest release of Workbench 10.1.822. It has become somewhat easier, therefore I also created an automated script for my usecase. Feel free to use it: (* Directory containing html folder, e.g. C:/project/build/...


12

ClearAll[YandexTranslate]; YandexTranslate[string_String, lang_String, apikey_String: apikey] := StringCases[ URLFetch[ "https://translate.yandex.net/api/v1.5/tr.json/translate?key=" <> apikey <> "&text=" <> string <> "&lang=" <> lang <> "&format=plain" ], "[\"" ~~ x___ ~~ "\"]}" :>...


11

The different HTML entities are stored in System`Convert`MLStringDataDump`$HTMLEntities on version 9 and from here, it's a simple StringReplace: StringReplace["<select></select>", System`Convert`MLStringDataDump`$HTMLEntities] (* "&lt;select&gt;&lt;/select&gt;" *)


10

This is an issue with XOWA. The HTTP Server was rewritten in v2.7.2 to handle POSTs and other features. However, it looks like it crashes on your request. I'll look at fixing this for v2.8.2. I'll comment again here when I have a resolution, but feel free to contact me directly for more info. Hope this helps! [Edit: This was fixed for v2.8.2. XOWA now ...


10

This will download the titles of all articles that transclude the Persondata template, if that's what you're trying to do. Flatten@NestWhileList[ Import["http://en.wikipedia.org/w/api.php?action=query&list=\ embeddedin&eititle=Template:Persondata&format=json&eilimit=500" <> If[Length@# > 1, "&eicontinue=" <> #[[2,...


10

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"> ...


9

Something like: ExportString[Cell[TextData["<select></select>"],"Text"],"HTML","FullDocument" -> False] produces: <p class="Text"> &lt;select&gt;&lt;/select&gt; </p> which might also be a good start.


9

Partial Solution Wolfram Workbench 2 and 3 are not able to launch the front end (Mathematica 10+) to create the final HTML. The solution is to use the new (Eclipse-plugin) version, downloadable from: https://www.wolfram.com/workbench/. Which is also free when you have purchased a Mathematica license. Some issues with the HTML edit: I took the time to ...


8

For the benefit of those who come across this old question, I have recently written a small open-source library called MathCell that replicates the behavior of Mathematica's Manipulate using pure JavaScript. Documentation is available here. The library is not for converting Mathematica code, but is meant as a replacement for people who want to embed ...


7

I haven't seen a clear cut solution listed anywhere even though this question is quite old. Thus, I will post my solution here. The easiest solution is to use SVG format rather than to fiddle with JPEG, GIF, or PNG format. filePath = "path of the file"; nb = Import[filepath]; Export["my3.html", nb, "HTML", "GraphicsOutput" -> "SVG", "MathOutput" -> "...


7

Your code works fine—the site is just very stringent on the data supplied. I used Chrome's Inspect Element to see the values of all the input elements (including the hidden fields, as you'd noticed)—and I found that sometimes codigoColegio was left blank: It didn't work when I filled out codigoColegio to match nivel as you seemed to have done, but it did ...


7

Store data in question Tables could be left in plain text, with some encoding to remove CR and LF characters and other symbols. EncodeForQuestion[expr_List] := CopyToClipboard[ StringJoin["<data payload=\"", URLEncode[ExportString[expr, "CSV"]], "\"/>"]] Arbitrary data can be expressed as plain text with InputForm and ToString or compressed ...


7

This is what it looks like for me when I try to export the grid as HTML: These are just the first couple of errors. It goes on like that. On the other hand, ExportString[exp, "HTMLFragment"] seems to work. A solution could then be to do something like this: html = ExportString[exp, "HTMLFragment"] SystemOpen@Export[ FileNameJoin[{$TemporaryDirectory, "...


7

To be clear, this isn't about data that is Missing[] (in which case, you would use DeleteMissing), but rather Import[XXXX,{"HTML", "Data"}] returning "tables" that have rows with inconsistent lengths. You can solve this by importing "FullData" rather than "Data". dataA1 = Import[ "http://www.nuforc.org/...


6

The answer in general is no, and I've also wished there was a simple way to do it. The only exception I know of is when you export a notebook with a ContoutPlot or ListContourPlot to HTML, as in this question. The exported GIF image actually contains a reference to an image map which is a very old-fashioned way of providing tooltip information in images ...


6

Here is a workaround which works for me. On version 11.2, windows 7 SetDirectory[NotebookDirectory[]]; If[Not[DirectoryQ["test"]], CreateDirectory["test"] ]; Export[ "test", (*saved in this folder below current folder*) Notebook[{ Cell["testing","Section"], Cell[BoxData[ButtonBox[RowBox[{"Back to Interesting Science"}], BaseStyle->"...


6

Let's step back and do something simpler: Import["https://duckduckgo.com/?q=%22Wolfram%22&t=h_&ia=web"] (* "Ignore this box please. DuckDuckGo You are being redirected to the non-JavaScript site. Click here if it doesn't happen automatically." *) Oh, you are been redirected! To where? Import[ "https://duckduckgo.com/?q=%22Wolfram%22&t=h_&...


6

You can capture all consecutive events like this: xmldata1 = Cases[xmldatatest, XMLElement[ "series", {}, {XMLElement[ "header", {}, {XMLElement["type", {}, {aa_}], XMLElement["moduleInstanceId", {}, {bb_}], XMLElement["locationId", {}, {cc_}], XMLElement["parameterId&...


5

Finally, after many attempts, I had the answer: the ConversionOptions have to be assigned to "XHTML" and not to "HTML". Indeed, this works: ConversionOptions->{ "ExportOptions"->{"XHTML" -> {"ConversionRules" -> {"ItemNumbered" -> {"<li>", "</li>"}, "Text" -> {"<p class=\"mytext\">", "</p>"}}, ...


5

I've created test image with Heike's code from How to create word clouds? and I've posted it... here :): So let's download it: pic = Import["http://i.stack.imgur.com/Ni4Kl.png"]; In case of full html you can use Import[....html, "Images"]. TextRecognize[ImageResize[pic, {Automatic, 1100}]] Not perfect but it's something. It is String so after ...


5

I don't know what causes the issue (which looks like a bug to me), but I generally find the best way to deal with exerting control over Import not doing quit the right thing with HTML is to use the "XMLObject" element and use ordinary Mathematica functions on it, like so: In[1]:= ImportString@ ExportString[ ImportString["a<span>b<...


5

Updated Using ToBoxes@Column[{Row[{"test", "1"}]}] we get TagBox[GridBox[{{TemplateBox[{"\"test\"", "\"1\""}, "RowDefault"]}}, <<omitted output>> That TemplateBox is strange because Row should have translated into RowBox. Let us force it: kubaExport[x_] := ExportString[ ToBoxes@x /. TemplateBox[a_, "RowDefault"] :> RowBox[a] // ...


5

I figure it's good to avoid trying to parse the String manually when we can have Mathematica turn it into an XMLObject for us with ImportString[string, {"HTML","XMLObject"}] which lends itself to more reliable parsing. It's not really simpler but should give less headaches down the line. Here is a quick demonstration, modifyXMLAttributes takes an XMLElement ...


5

This thing could be done by the option "MathOutput"->"InputForm", However I'm not sure whether this can entirely solve the question(need more tests). Export["test.html", nb = EvaluationNotebook[], "HTML", "ConversionRules" -> {"Input" -> {"<pre><code>", "</code></pre>"}}, CharacterEncoding -> "CP936", "...


5

I think HTML export in Mathematica is based on standards that date back to way before anyone had even heard of HTML5. E.g., the Import docs for HTML say it understands HTML 4.01. Fortunately, even then there was already support for accents that required only ASCII characters. These are the HTML entities &egrave; etc. Because they come from a time in ...


5

HTML >> Import Elements So you can use "FullData" in place of "Data": ImportString["<table> <tr> <th>Firstname</th> <th>Lastname</th> <th>Age</th> </tr> <tr> <td> </td> <td>Smith</td> <td>50</td> </...


4

These are CellLabels and by default they are autodeleted when Notebook is saved. To preserve them, evaluate the following: SetOptions[EvaluationNotebook[], CellLabelAutoDelete -> False]


4

Ok well I found an obvious way to do it.. simply make the font bigger. The exported image scales up with the font size. Can Edit Stylesheet.. to change the size of the body font for the whole workbook.


Only top voted, non community-wiki answers of a minimum length are eligible