basic import.io html search

帅比萌擦擦* 提交于 2019-12-11 03:40:21

问题


So if any of you have any experience with scraping or particularly import.io it will help, since import.io is what i'm using... although I think my question is just about JS really...

I really just want to connect a basic html input to the import.io JS code so I can have a custom search

http://jsfiddle.net/LSng3/1/

"input": {
      var search_name = document.getElementsByName("search_name").value;
      "search_name": search_name
}

<input name="search_name" placeholder="doesnt work :(">

Heres my go... its the basic working import.io JS example. I tried to add a variable for the input name and add the variable as the search item but that alone isnt working...

I contacted the import.io team and they said they will try to make a easier tutorial in the future but for now try to look at the particle example they have which does include a input to search with but the example is too big for me to deconstruct just to see how the input works.

heres the particle example I uploaded to my server so you can see it working although its a bit slow-> http://www.originalengine.com/scrape/


回答1:


Please find here a modified version of your code which seems to produce the correct result: http://jsfiddle.net/zNSbk/

This is the modified function:

var doTestQuery = function() {
  // Query for tile myTestScrape2
  var search_name = document.getElementById("myInput").value;
  console.error(search_name);
  importio.query({
    "connectorGuids": [
      "a2201b40-7acc-4a3d-a3ed-30e71e018ffa"
    ],
    "input": {
      "search_name": search_name
    }
  }, { "data": dataCallback, "done": doneCallback });
}

Steps that I took to get this working (not all may be required but it is a summary of what I was playing with):

  • Redefined the function called by the submit so there's no possible collision with the one that we defined in the script
  • Moved the creation of "search_name" variable out of the JSON argument to importio.query
  • Assigned an ID to the input and used that with getElementById rather than using the name (as this would return an array)


来源:https://stackoverflow.com/questions/23976303/basic-import-io-html-search

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!