模拟之前点击

时间:2018-08-07 18:43:11

标签: javascript web-scraping wixcode

我有一个网站,我正在尝试从https://www.shapiro-ingle.com/sales.aspx?state=NC抓取数据。不幸的是,我必须单击“搜索”,然后页面上的表格才会填充我需要的信息。该URL也保持不变。因此,当我运行获取数据获取源代码时,它不包含我需要的数据。

是否有一种简单的方法来触发诸如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";
      }
      });
    }

1 个答案:

答案 0 :(得分:1)

创建鼠标事件并将其分配给所需的元素

// <body ng-app='myApp' binds to the app being created below.
var app = angular.module('myApp', []);
app.directive('replaceLinks', ['$compile', function($compile) {
  return {
    restrict: 'A',
    link: function(scope, element, attrs) {
      angular.forEach(element.find("a"), function(link) {
        link.setAttribute("href", "");
        link.removeAttribute("target");
        link.setAttribute("ng-click", "scopeAlert('test')");
      });
      $compile(element.contents())(scope);


    }
  };
}]);
// Register MyController object to this app
app.controller('MyController', ['$scope', MyController]);

// We define a simple controller constructor.
function MyController($scope) {
  // On controller load, assign 'World' to the "name" model
  // in <input type="text" ng-model="name"></input>
  $scope.name = 'World';
  $scope.scopeAlert = function(name) {
    window.alert(name);
  }
}

编辑:

将POST发送到表单端点

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-controller='MyController' ng-app="myApp">
  <div replace-links>
    <a href="#">test 1</a>
    <a href="#">test 2</a>
    <a href="#">test 3</a>
  </div>
</div>