Skip to content
Advertisement

Scrape currency exchange data from https://uzmanpara.milliyet.com.tr/doviz-kurlari/

I need get the currency data from website, here the website HTML table code:

JavaScript

I wrote these code but I could not handle the code:

JavaScript

But I got this problem:

Exception in thread “AWT-EventQueue-0” java.lang.NullPointerException: Cannot invoke “org.jsoup.nodes.Element.attr(String)” because “link” is null

How can I handle this problem, how can I get currency rate.

Advertisement

Answer

You can try like this:

JavaScript

If you just type href, it will search for the href tagname, but there is never such a tagname. You have to look for the href attribute of the a tag.

Let’s start with a simple example.

Example, to get the value of the 2nd span below the element whose href value is /dolar-kuru/, you can try:

JavaScript

We can take the example one step further.

Let’s take both the buy and sell prices from a table of exchange rates.

JavaScript

Will give an output that looks like this:

JavaScript

More different selectors can be used, see. https://jsoup.org/cookbook/extracting-data/selector-syntax

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement