question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] Code similar to exemple produce error

See original GitHub issue

Describe the bug I’m using the following

it.link = span {
                    withClass = "lchx"
                    findFirst {
                        a { findFirst { attribute("href") }}
                    }
                }

and I get 'fun <T> Doc.a(cssSelector: String = ..., init: CssSelector.() -> String): String' can't be called in this context by implicit receiver. Use the explicit one if necessary

Expected behavior No error and it.link is set to the value of the href attribute.

Full Code

import it.skrape.core.fetcher.Method
import it.skrape.core.fetcher.Mode
import it.skrape.core.htmlDocument
import it.skrape.extractIt
import it.skrape.selects.html5.span
import it.skrape.selects.html5.a
import it.skrape.skrape
 
    data class MyExtractedChapter(
        var text: String = "",
        var link: String = ""
    )
fun main() {
    val extracted = skrape {
        url = "https://someurl.com"
        mode = Mode.DOM // optional -> defaults to SOURCE (plain http request) - DOM will also render JS
        method = Method.GET // optional -> defaults to GET
        timeout = 5000 // optional -> defaults to 5000ms
        followRedirects = true // optional -> defaults to true
        userAgent = "some custom user agent" // optional -> defaults to "Mozilla/5.0 skrape.it"
        cookies = mapOf("some-cookie-name" to "some-value") // optional
        headers = mapOf("some-custom-header" to "some-value") // optional

        extractIt<MyExtractedChapter> { it ->
            htmlDocument {

                it.text = span {
                    withClass = "lchx"
                    findFirst {
                        text
                    }
                }

                it.link = span {
                    withClass = "lchx"
                    findFirst {
                        a { findFirst { attribute("href") } }
                    }
                }
            }
        }
    }
}

Note: I based myself on this part of the doc https://github.com/skrapeit/skrapeit-docs/blob/1.0.0-alpha6/dsl/extracting-data-from-websites.md And it appears the exemple does not compile.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
Drikycommented, Sep 20, 2020

Indeed with experimental features activated my code works !

0reactions
christian-draegercommented, Sep 21, 2020

no unfortunately not. but api wise the usage und functionality (also element nesting) will not change in 1.0.0-final release. only thing that will be different is how to define requests (but also in the master and documented in the master README file already). only reason that 1.0.0-final isnt released is an ongoing project structure refactoring to be a multi module project in preparation for upcoming features.

Read more comments on GitHub >

github_iconTop Results From Across the Web

7 types of software bugs and errors | The Jotform Blog
Knowing about the different types of software bugs can help you quickly address them and get back to developing. Here are the main...
Read more >
PROGRAM BUG EXAMPLES - Courses
Some compilers spot no-initialization errors. Note that an improper initialization, while rarer, is even harder to spot than a missing one! EXAMPLE 3:...
Read more >
The 7 Most Common Types of Errors in Programming and ...
4. Runtime Errors. Runtime errors happen as a user is executing your program. The code might work correctly on your machine, but on...
Read more >
What is a bug (computer bug)? - TechTarget
In computer technology, a bug is a coding error in a computer program. ... One of example of a logic error is an...
Read more >
7 Types of Software Errors That Every Tester Should Know
In this article, we will be discussing common software errors and how to identify them during testing with examples and simple exercises.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found