模拟点击之前

Simulate Click before

我有一个网站,我正试图从 https://www.shapiro-ingle.com/sales.aspx?state=NC 抓取数据。不幸的是,在页面上的 table 填充我需要的信息之前,我必须单击 "Search"。 URL 也保持不变。因此,当我 运行 使用 fetch 获取源代码时,它不包含我需要的数据。

有没有简单的方法来触发类似 document.getElementById("SubmitBtn").click();在 httpResponse 发生之前加载我需要的数据?

  export function data_scrape(url) {
       return fetch(url, {method: 'get'})
      .then( (httpResponse) => {
        if (httpResponse.ok) {
          return httpResponse.text();
      } else {
        return "Error";
      }
      });
    }

创建鼠标事件并将其分派到所需的元素

var elem = document.getElementById("SubmitBtn")
var click = new MouseEvent('click', {
    view: window
});
elem.dispatchEvent(click);

编辑:

发送POST到表单端点

// db can be upcoming_sales or sales_held
// county can be any of the options in the drop down
var data = "db=upcoming_sales&county=Alamance" 

fetch(url, {
    method: "POST"
    headers: {
        "Content-Type": "application/x-www-form-urlencoded",
    },
    body: JSON.stringify(data),
}).then(...)