我有一个网站,我试图从https://www.shapiro-ingle.com/sales.aspx?state=NC刮数据。不幸的是,在页面上的表格将填充我需要的信息之前,我必须单击"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";
}
});
}发布于 2018-08-07 18:51:03
创建鼠标事件并将其分派给所需的元素
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(...)https://stackoverflow.com/questions/51733454
复制相似问题