Skip to content

Commit

Permalink
Fix ScienceDirect fetcher #3854
Browse files Browse the repository at this point in the history
  • Loading branch information
stefan-kolb committed Mar 15, 2018
1 parent 0ff2ac1 commit 3a923eb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
11 changes: 11 additions & 0 deletions src/main/java/org/jabref/logic/importer/fetcher/ScienceDirect.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -53,7 +54,16 @@ public Optional<URL> findFullText(BibEntry entry) throws IOException {
.referrer("http://www.google.com")
.ignoreHttpErrors(true).get();

// Retrieve PDF link from meta data (most recent)
Elements metaLinks = html.getElementsByAttributeValue("name", "citation_pdf_url");

if (!metaLinks.isEmpty()) {
String link = metaLinks.first().attr("content");
return Optional.of(new URL(link));
}

// Retrieve PDF link (old page)
// TODO: can possibly be removed
Element link = html.getElementById("pdfLink");

if (link != null) {
Expand All @@ -62,6 +72,7 @@ public Optional<URL> findFullText(BibEntry entry) throws IOException {
return pdfLink;
}
// Retrieve PDF link (new page)
// TODO: can possibly be removed
String url = html.getElementsByClass("pdf-download-btn-link").attr("href");

if (url != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ void findByDOIOldPage() throws IOException {
entry.setField("doi", "10.1016/j.jrmge.2015.08.004");

assertEquals(
Optional.of(new URL("http://www.sciencedirect.com/science/article/pii/S1674775515001079/pdfft?md5=2b19b19a387cffbae237ca6a987279df&pid=1-s2.0-S1674775515001079-main.pdf")),
Optional.of(new URL("https://www.sciencedirect.com/science/article/pii/S1674775515001079/pdfft?md5=2b19b19a387cffbae237ca6a987279df&pid=1-s2.0-S1674775515001079-main.pdf")),
finder.findFullText(entry)
);
}
Expand All @@ -42,7 +42,7 @@ void findByDOINewPage() throws IOException {
entry.setField("doi", "10.1016/j.aasri.2014.09.002");

assertEquals(
Optional.of(new URL("http://www.sciencedirect.com/science/article/pii/S2212671614001024/pdf?md5=4e2e9a369b4d5b3db5100aba599bef8b&pid=1-s2.0-S2212671614001024-main.pdf")),
Optional.of(new URL("https://www.sciencedirect.com/science/article/pii/S2212671614001024/pdf?md5=4e2e9a369b4d5b3db5100aba599bef8b&pid=1-s2.0-S2212671614001024-main.pdf")),
finder.findFullText(entry)
);
}
Expand Down

0 comments on commit 3a923eb

Please sign in to comment.