Skip to content

Commit

Permalink
Revert "Change code to spawn browser to be more human likely"
Browse files Browse the repository at this point in the history
This reverts commit 4970fa1.
  • Loading branch information
davidasync committed Sep 13, 2018
1 parent 4970fa1 commit dccac02
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 146 deletions.
26 changes: 0 additions & 26 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,35 +44,9 @@ jar {
}
}

installDist {
into('bin') {
from '.'
include 'webdrivers/*'
}
}

dependencies {
// https://mvnrepository.com/artifact/org.jsoup/jsoup
compile group: 'org.jsoup', name: 'jsoup', version: '1.11.3'

compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"

// https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient
compile group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.6'

// https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java
compile group: 'org.seleniumhq.selenium', name: 'selenium-java', version: '3.13.0'

// https://mvnrepository.com/artifact/commons-io/commons-io
compile group: 'commons-io', name: 'commons-io', version: '2.5'

// https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-core
compile group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.9.6'

// https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind
compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.9.6'

// https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient
compile group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.6'

}
46 changes: 31 additions & 15 deletions src/main/kotlin/com/desolator/Main.kt
Original file line number Diff line number Diff line change
@@ -1,23 +1,39 @@
package com.desolator

import com.desolator.helpers.login
import com.desolator.lib.dinkIt
import com.desolator.utils.initBrowser
import org.jsoup.Connection
import org.jsoup.Jsoup
import java.util.*

object Main {
@JvmStatic
// dinkit [email] [password] [product detail url]
fun main(args: Array<String>) {
val (email, password, productDetailUrl) = args
val driver = initBrowser(true)

try {
login(driver, email, password)
dinkIt(driver, productDetailUrl)
} catch (e: Exception) {
e.printStackTrace()
} finally {
driver.close()
if (args.size < 3) {
println("Should email password and product id to execute!")
return
}

val (email, password, productId) = args
val tokopediaLoginUrl = Jsoup.connect("https://www.tokopedia.com/login").followRedirects(true).execute()
val headers = hashMapOf(
"content-type" to "application/x-www-form-urlencoded",
"origin" to "https://accounts.tokopedia.com",
"referer" to tokopediaLoginUrl.url().toString(),
"user-agent" to "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.87 Safari/537.36 OPR/54.0.2952.54"
)

val loginRes = Jsoup.connect(tokopediaLoginUrl.url().toString())
.headers(headers)
.cookies(tokopediaLoginUrl.cookies())
.data("email", email, "password", password, "remember_me", "on")
.method(Connection.Method.POST)
.execute()

val milliseconds = Calendar.getInstance().timeInMillis
val dinkItUrl = "https://www.tokopedia.com/ajax/product-e4.pl?action=event_dink_it&p_id=${productId}&v=${milliseconds}"
val dinkItResult = Jsoup
.connect(dinkItUrl)
.cookies(loginRes.cookies())
.get()

println(dinkItResult)
}
}
83 changes: 0 additions & 83 deletions src/main/kotlin/com/desolator/helpers/Login.kt

This file was deleted.

22 changes: 0 additions & 22 deletions src/main/kotlin/com/desolator/lib/dink-it.kt

This file was deleted.

0 comments on commit dccac02

Please sign in to comment.