Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    srid
    @srid:matrix.org
    [m]
    Oddly enough, the HtmlBodyElement has the correct BaseUrl but the value of OutterHtml is a mere "<body></body>". Hmm, that might be it.
    Or not, as I see the same behaviour with other URLs.
    1 reply
    srid
    @srid:matrix.org
    [m]
    @FlorianRappl: I followed the README example on github, to load the Wikipedia URL.

    But when I just tried with local content, it works:

    
    let getDoc (htmlContent: string) = 
        let cfg = Configuration.Default.WithDefaultLoader()
        let ctx = BrowsingContext.New(cfg)
        async { return! ctx.OpenAsync(fun req -> req.Content(htmlContent) |> ignore) |> Async.AwaitTask } |> Async.RunSynchronously
    
    [<EntryPoint>]
    let main argv =
        let doc = getDoc "<body><div>Hello</div></body>"
        let cells = doc.QuerySelectorAll("div")
        let titles = query {
                for cell in cells do
                    select cell.TextContent
            }
        printfn $"Printing {Seq.length titles} titles"
        for title in titles do
            printfn $"Title: {title}"
        0 // return an integer exit code

    ^ This works, which is good enough I guess, as I don't plan to load remote content anyway.

    srid
    @srid:matrix.org
    [m]
    By the way, as a new F# dev (and being completely new to dotnet ecosystem; but familiar with FP), the main reason I'm exploring AngleSharp is to figure out how useful it would be for writing my own HTML templating language (based on XML'ish stuff; so stuff like partials & layout and variables are defined the XML way).
    srid
    @srid:matrix.org
    [m]

    Is it possible to get the contents of a <template> tag (so as to query on it)?

    In JS, you would do it using the .content property.

    Eg: to query the td inside the <template> tag of https://developer.mozilla.org/en-US/docs/Web/HTML/Element/template#examples
    (or even get the whole contents of template as its own document)
    Florian Rappl
    @FlorianRappl
    Yes definitely.
    srid
    @srid:matrix.org
    [m]
    I tried let tmpl = doc.QuerySelectorAll("template"), which returns the template tag, but I can't drill down further than.
    Florian Rappl
    @FlorianRappl
    Why - its an HTMLTemplateElement - just cast the result to the right type
    Sorry but C# / F# are no dynamic languages like JS. So you need to get the types right ;)
    srid
    @srid:matrix.org
    [m]
    fwiw, here's my current code:
        let templates = doc.QuerySelectorAll("template")
        let titles =
            query {
                for tmpl in templates do
                    for p in tmpl.QuerySelectorAll("p") do
                        select p.OuterHtml
            }
    titles is empty seq, so the "p" querying didn't work, which isn't surprising I guess, because I'm suppose to get the fragment inside tmpl and then query on it.
    Florian Rappl
    @FlorianRappl
    Yes you need to query the fragment - your current query works against children of templates, not the content in the template
    srid
    @srid:matrix.org
    [m]
    My assumption is that I need a filler in here: tmpl.GetContentFragment().QuerySelectorAll("p") - but what would be GetContentFragment?
    Don't see anything relevant in auto-completion list for tmpl.
    Not sure what GetContentFragment is / should be. I guess you want Content?
    srid
    @srid:matrix.org
    [m]
    Right! That must be it; now I gotta figure out casting in F# ...
    QuerySelectorAll returns a collection of IElement. I should cast that to IHtmlTemplateElement
    Wait, you can't down cast it. Looking for polymorhpic querying ... (is that anti-pattern in dotnet)
    Florian Rappl
    @FlorianRappl
    1. Either use QuerySelector or iterate over all results (not sure if you interested in a single one or all results).
    2. Check the type before casting it.
    srid
    @srid:matrix.org
    [m]
    QuerySelector looks interesting - let me see how I can use it to pull multiple <template> tags
    Wait, I thought that's more polymorphic that QuerySelectorAll - but the difference is only in arity

    I was trying something like the following so as to obviate having to cast things latter:

        let templates : IHtmlCollection<IHtmlTemplateElement> =
            doc.QuerySelectorAll<IHtmlTemplateElement>("template")

    But this just throws a

    error FS0001: This expression 
    was expected to have type↔    'IHtmlCollection<IHtmlTemplateElement>'    ↔but here has type↔    'Collections.Generic.IEnumerable<IHtmlTemplateElement>
    Oh wait, wrong collection type
    Ah, now it worked! Using System.Collections.Generic. Polymorphism for the win.
    srid
    @srid:matrix.org
    [m]

    As an aside, it seems that I'm reinventing XSLT, as it appears to do the 'templating' feature I'm trying to build from scratch: https://developer.mozilla.org/en-US/docs/Web/API/XSLTProcessor/Basic_Example

    (My idea uses JSON as data input; but XSLT uses XML as data input, which might be more interesting when used with AngleSharp)

    Tako
    @Takoooooo
    image.png
    Hello guys. I have such code. I would like to click programmatically on the button and it should redirect me to the main GitHub page, but somewhy it doesn't redirect me at all. Maybe you can help me?
    from console it works,but from c# somewhy it doesent
    Tako
    @Takoooooo
    is it at least possible to make anglesharp follow redirects?
    Tako
    @Takoooooo
    @FlorianRappl
    Florian Rappl
    @FlorianRappl
    The default requesters follow redirects properly.
    Marko Lahma
    @lahma
    a suggestion for the version list https://www.nuget.org/packages/AngleSharp/ , maybe unlist some old alphas and pad build number (?) with zeroes to get stable ordering, it's a bit confusing :wink:
    1 reply
    Egil Hansen
    @egilhansen:matrix.org
    [m]
    I started pushing night builds to github package repository instead to avoid that sillyness
    1 reply
    Egil Hansen
    @egilhansen:matrix.org
    [m]
    True, although nuget.org does send me notifications by email when a key is about to expire.
    5 replies
    Marko Lahma
    @lahma
    Would the project accept a PR to switch to BenchmarkDotNet for performance testing instead of the custom solution? Might give more accurate results with better visibility to memory usage.
    4 replies
    Egil Hansen
    @egilhansen:matrix.org
    [m]
    @FlorianRappl: I bumped the version of diffing to 0.15.0 in the directory props file, but it still seem to be creating 0.14.0 packages. Do you have any idea way?
    2 replies
    martin-honnen
    @martin-honnen

    Does anyone know why the sample

    
            static async Task Main()
            {
                var jsService = new JsScriptingService();
    
                var config = Configuration.Default.With(jsService);
    
                var context = BrowsingContext.New(config);
    
                var source = "<!DOCTYPE html><html><head><title>Test</title><script>function f1(el) { document.body.appendChild(el); }</script></head><body><h1>Some example source</h1><p>This is a paragraph element.</p><script>var em1 = document.createElement('em'); em1.textContent = 'This is some emphasized text.'; f1(em1);</script></body></html>";
    
                var document = await context.OpenAsync(req => req.Content(source));
    
                Console.WriteLine("Serializing the (original) document:");
                Console.WriteLine(document.DocumentElement.OuterHtml);
    
                var f1 = jsService.GetOrCreateJint(document).GetValue("f1");
    
                var bElement = document.CreateElement("b");
                bElement.TextContent = "This is some bold text.";
    
                var jsB = JsValue.FromObject(jsService.GetOrCreateJint(document), bElement);
    
                f1.Invoke(jsB);
    
                Console.WriteLine("Serializing the document again:");
                Console.WriteLine(document.DocumentElement.OuterHtml);
            }

    gives a JavaScript exception

    Jint.Runtime.JavaScriptException
      HResult=0x80131500
      Message=
      Source=jint
      StackTrace:
       at Jint.Native.Function.ScriptFunctionInstance.Call(JsValue thisArg, JsValue[] arguments)
       at Jint.Native.JsValue.Invoke(JsValue thisObj, JsValue[] arguments)
       at Jint.Native.JsValue.Invoke(JsValue[] arguments)

    on the f1.Invoke(jsB) call? I use release 0.15 of AngleSharp and 0.14 of AngleSharp.Js

    Adeel Rizvi
    @syedadeel2
    Hello, Is there a way to get the rendered HTML rather template? i have website using vuejs and what I'm getting all its un-rendered template rather than actual binded elements
    Egil Hansen
    @egil
    Hey @FlorianRappl, thanks for the help with the element name casing the other day. A few related questions:
    1. Is it possible to retain the casing of attributes as well?
    2. Is it possible to configure AngleSharp to allow custom elements to be self closing?
    5 replies
    Also, we talked previously about github release workflows. For bUnit, I have something I am pretty happy with. Here is a boilerplate repo that has the bare minimum and an explanation of whats going on: https://github.com/bUnit-dev/workflows
    martin-honnen
    @martin-honnen
    Is the AngleSharp.Url class supposed to be exposed to JavaScript as the URL (https://developer.mozilla.org/en-US/docs/Web/API/URL) constructor? I am trying to load an HTML document using JavaScript with AngleSharp 0.15 and AngleSharp.Js 0.14 and get a script error "ReferenceError: URL is not defined" from jint. Is there anything required or any way possible to have URL defined in JavaScript based the AngleSharp.Url class?
    3 replies
    martin-honnen
    @martin-honnen
    Does anyone here know why https://github.com/AngleSharp/AngleSharp.XPath/tags only has releases up to 1.1.5 but NuGet shows two additional releases 1.1.6 and 1.1.7? Where is the repository for those two latest releases?
    1 reply
    martin-honnen
    @martin-honnen
    Are AngleSharp packages supposed to be compatible with .NET framework? So far what I have tried and seen seemed to target .NET Standard 2.0 so that it should work with .NET framework but the latest change to the XPath package in https://github.com/AngleSharp/AngleSharp.XPath/commit/dfd9d33a7eb0201de6a7229ee13a4adcb37f926c#diff-615740254f47d7a152d8b39cff4d7b49d0aa3db2821f2f67ebe6f13ad0ab45beR10 seems to indicate a move to .NET 5.
    1 reply
    Egil Hansen
    @egilhansen:matrix.org
    [m]
    Hey Florian, i tried to push a 0.16.0 of diffing, but it just pushed a 0.15.0 preview. Think i did things correctly. Updated csproj Version and merged with master. What am I missing?
    1 reply
    Egil Hansen
    @egilhansen:matrix.org
    [m]
    Yes, thanks, that's it.
    Shimmy
    @weitzhandler
    Hi,
    Anyone around?
    I'm trying to scarpe an Angular website where the actual data is loaded with JS, I tried calling .WithJavaScript on the configuration, but that line gives a TypeLoaderException