https://discord.cloudflare.com logo
Join Discord
Powered by
# workers-discussions
  • k

    kristian

    01/29/2021, 6:23 PM
    hey all! re: our workers q&a session on monday: we'll be streaming on cloudflare tv! link will be coming a little later today. if you're going to participate in the feb 1st q&a, please ask your questions 👉 #804778321580654672 see you there!
  • p

    Peps

    01/29/2021, 7:48 PM
    Registering a domain at Cloudflare directly is currently not possible yet
  • p

    Peps

    01/29/2021, 7:48 PM
    it is being worked on though
  • a

    advaith

    01/29/2021, 8:41 PM
    I had the feature for a while then it disappeared
  • p

    Peps

    01/29/2021, 8:49 PM
    yeah there was a beta for a bit
  • u

    617a7a

    01/29/2021, 9:13 PM
    hi all, have you checked out https://runkod.com
  • m

    Mary Johanna

    01/29/2021, 9:49 PM
    Hey, cf workers are amazing, however I can't seem to find an easy solution for html parsing. I don't wanna go for regexes because they are easy to break if the source changes. I found https://developers.cloudflare.com/workers/runtime-apis/html-rewriter too but this one is way too complicated to use. It works, but the meh category. How do you guys do it?
  • e

    Electroid

    01/29/2021, 10:01 PM
    Mind sharing the difficulties you've run into the API? What do you want to do with it?
  • m

    Mary Johanna

    01/29/2021, 10:03 PM
    Certainly, though I am a beginner so it's might be only me missing the point
  • m

    Mary Johanna

    01/29/2021, 10:03 PM
    Basically what I wanted to accomplish is to make a request to a specific url, get its body and then certain elements' values using xpath or css selectors
  • m

    Mary Johanna

    01/29/2021, 10:05 PM
    I have to do so many iterations to find out which one is the element I need and its quite hard without helper variables right now as you have an element scope...
  • m

    Mary Johanna

    01/29/2021, 10:06 PM
    Plus I would prefer to keep the "parser" object so I can do further parsing with it later in the code
  • m

    Mary Johanna

    01/29/2021, 10:06 PM
    Right now it seemed to be difficult unless I copy the whole object
  • c

    Ceru ©

    01/29/2021, 10:07 PM
    you could import something like Cheerio if you really want to use JQuery like syntax
  • c

    Ceru ©

    01/29/2021, 10:08 PM
    actually, something like that API for the HTMLRewriter would be amazing
  • m

    Mary Johanna

    01/29/2021, 10:19 PM
    Yeah I am really surprised there is none made
  • m

    Mary Johanna

    01/29/2021, 10:19 PM
    I don't think it will be part of the official JS but oh well, workers are in a way unique as there is no CORS so there is plenty to do with parsing
  • m

    Mary Johanna

    01/29/2021, 10:20 PM
    So even if its not standardized a custom solution would be more than awesome
  • m

    Mary Johanna

    01/29/2021, 10:20 PM
    Would make the code a lot cleaner to read if we could do things like
  • m

    Mary Johanna

    01/29/2021, 10:21 PM
    new HTMLParser(content).body.getElementByXPath("/a...").href
  • c

    Ceru ©

    01/29/2021, 10:30 PM
    or even
    $(await fetch('url')).find('a').setAttr('href', 'Hi')
  • g

    Greg Brimble | Cloudflare Pages

    01/29/2021, 10:35 PM
    url: https://cloudflareworkers.com/#6aced3f2a9c4febf429ddb3408e555c3:https://tutorial.cloudflareworkers.com title: Override a link href
  • c

    Cloudflare Workers Bot

    01/29/2021, 10:35 PM
    Copy code
    javascript
    class LinkHandler {
      element(element) {
        element.setAttribute('href', 'https://gregbrimble.com/')
      }
    }
    
    addEventListener('fetch', event => {
      event.respondWith(handleRequest(event.request))
    })
    
    /**
     * Fetch and log a given request object
     * @param {Request} request
     */
    async function handleRequest(request) {
      console.log('Got request', request)
      const response = await fetch(request)
      return new HTMLRewriter().on('a', new LinkHandler()).transform(response)
    }
  • g

    Greg Brimble | Cloudflare Pages

    01/29/2021, 10:36 PM
    Does that do the sort of thing you're after?
  • c

    Ceru ©

    01/29/2021, 10:37 PM
    yea but its not very easy for the new user
  • c

    Ceru ©

    01/29/2021, 10:37 PM
    im making somethin quick
  • c

    Ceru ©

    01/29/2021, 10:50 PM

    https://nyc3.digitaloceanspaces.com/cerulean/screenshots/2021/01/firefox_xBQRAvqAM6.png▾

  • c

    Ceru ©

    01/29/2021, 10:51 PM
    its dirty, but this is the first time ive done something like this
  • c

    Ceru ©

    01/29/2021, 10:53 PM
    plus this is cheaper than importing all of cheerio
  • k

    kristian

    01/29/2021, 11:15 PM
    AMAZING
1...767778...2509Latest