Email or username:

Password:

Forgot your password?
Simon Willison

My @covidsewage bot broke again after Santa Clara County changed the design of their publichealth.santaclaracounty. dashboard - you now have to click the "COVID" button inside the Power BI dashboard to get those charts, which is infuriatingly difficult because Power BI's idea of a "button" is a SVG path element with a click handler buried in a nest of weird HTML

Fixed it though! Details of the fix here: github.com/simonw/covidsewage-

- name: Extract iframe URL and generate screenshot
  run: |-
    url=$(shot-scraper javascript \
      'https://publichealth.santaclaracounty.gov/health-information/health-data/disease-data/covid-19/covid-19-wastewater' \
      'document.querySelector("iframe").src' \
      -b firefox \
      --user-agent 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:128.0) Gecko/20100101 Firefox/128.0' \
      --raw)
    echo "URL is $url"
    shot-scraper $url -o /tmp/covid.png -b firefox --retina --javascript '
    new Promise((takeShot) => {
      setTimeout(() => {
        // Find the <visual-modern> button with exact text COVID
        var el = Array.from(document.querySelectorAll(".ui-role-button-text"))
          .filter((el) => el.textContent.trim() == "COVID")[0]
          .closest("visual-modern");
        // Click everything in it to catch the <path> element
        function clickAllMatchingDescendants(rootElement, selector) {
          // Find all matching descendants
          const matchingElements = rootElement.querySelectorAll(selector);
          // Dispatch click event to each matching element
          matchingElements.forEach((element) => {
            element.dispatchEvent(
              new MouseEvent("click", {
                bubbles: true,
                cancelable: true,
                view: window,
              }),
            );
          });
        }
        clickAllMatchingDescendants(el, "path");
1 comment
Go Up