Skip to content

Commit

Permalink
get list of movie links
Browse files Browse the repository at this point in the history
  • Loading branch information
ratanparai committed Apr 25, 2019
1 parent 5498731 commit 33aba4f
Show file tree
Hide file tree
Showing 3 changed files with 1,189 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package com.ratanparai.moviedog.scrapper

import com.ratanparai.moviedog.db.entity.Movie
import org.jsoup.Jsoup
import org.jsoup.nodes.Document
import java.io.IOException
import java.util.*
import java.util.concurrent.TimeUnit
import kotlin.collections.ArrayList

class DekhvhaiScrapper {

Expand Down Expand Up @@ -81,6 +83,16 @@ class DekhvhaiScrapper {

}

fun getListOfMovieLinksFromSearchResult(document: Document): List<String>{
val result = ArrayList<String>()
val elements = document.select("#tabs_i2-pane1 > div > a")
for (elem in elements) {
result.add(elem.attr("href"))
}

return result
}


fun getOnlyTitleFromTitleAndYear(titleWithyear: String): String {
return titleWithyear.substring(0, titleWithyear.indexOf("(")).trim { it <= ' ' }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
package com.ratanparai.moviedog.scrapper

import com.google.common.truth.Truth.assertThat
import org.jsoup.Jsoup
import org.jsoup.nodes.Document
import org.junit.Before
import org.junit.Test
import java.io.File

class DekhvhaiScrapperTest {

private lateinit var dekhvhai: Document

@Before
fun loadHtml() {
val file = ClassLoader.getSystemResource("HarryPotter_Dekhvhai.html").readText()

dekhvhai = Jsoup.parse(file, "UTF-8")
}

@Test
fun shouldGetCorrectTitleFromTitleAndYear() {
// Arrange
Expand Down Expand Up @@ -51,4 +65,25 @@ class DekhvhaiScrapperTest {
assertThat(actual).isEqualTo(expected)

}

@Test
fun shouldLoadHtmlFileAsJsoupDocument() {
//val file = File("html/HarryPotter_Dekhvhai.html")
val file = ClassLoader.getSystemResource("HarryPotter_Dekhvhai.html").readText()

val document = Jsoup.parse(file, "UTF-8")

assertThat(document).isNotNull()
}

@Test
fun getMovieUrlsToBrowse() {
val scrapper = DekhvhaiScrapper()
val movieLinks = scrapper.getListOfMovieLinksFromSearchResult(dekhvhai)
assertThat(movieLinks.size).isEqualTo(4)

assertThat(movieLinks[0]).isEqualTo("http://dekhvhai.com/movie.php?imdbid=tt1201607&cat=English%20Movie")

}

}
Loading

0 comments on commit 33aba4f

Please sign in to comment.