2
$\begingroup$

I try to use jSoupLink to scrap data. However, I have difficulty in using ParseHTML commamd.

For example, I cant get the ParseHTML to work

ParseHTML[
 "https://www.nobelprize.org/nobel_prizes/physics/laureates/1921/einstein-facts.html", 
 "span[itemprop=birthDate]", 
 "text"
 ]

I would appreciate any help on this as I am new to jSoupLink.

$\endgroup$
6
  • 1
    $\begingroup$ ParseHTML is a syntax that was used in an old version of jsoupLink. Please see the documentation for the up syntax to be used with the current version. $\endgroup$
    – C. E.
    Commented Jan 22, 2020 at 9:41
  • $\begingroup$ Thanks for your clarification. May I further ask what will be the syntax when using about example ? $\endgroup$
    – Akcmok
    Commented Jan 22, 2020 at 11:18
  • $\begingroup$ You can try this: el = Import[url, "HTMLDOM"]; spans = el["Select", "span[itemprop=birthDate]"; birthDates = #["AllText"] & /@ spans; When looking at the URL in your question, I don't find any such span element, however. (Also, I haven't tried this code in Mathematica, which I don't have access to at the moment.) $\endgroup$
    – C. E.
    Commented Jan 22, 2020 at 11:49
  • 1
    $\begingroup$ By looking at the HTML code, you can tell that 1) the facts (e.g. year of birth) aren't wrapped in span elements, and 2) that the <p> tags that wrap facts do not have attributes that identify them. You'll have to look at other pages as well and see if you can find pattern. For example, el["Select", "article.facts p"] will (although I haven't tested it) give you a list of p elements where each element has a fact in it. Perhaps it's the case that the second of those elements is always the one with the year of birth. Perhaps there is no pattern, in which case... $\endgroup$
    – C. E.
    Commented Jan 24, 2020 at 11:14
  • 1
    $\begingroup$ ...you can use facts = el["Select", "article.facts"]; text = facts["AllText"]; and then parse the year of birth, and other facts, from that piece of text. $\endgroup$
    – C. E.
    Commented Jan 24, 2020 at 11:15

0

Your Answer

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

Browse other questions tagged or ask your own question.