0

I have the following url: https://www.amazon.com/#twotabsearchtextbox. When I click on this link I would like it to go to Amazon, select the search bar, and input a value. My question is: how do I modify the URL to insert a value into the search bar?

Example Input

URL: https://www.amazon.com/#twotabsearchtextbox

Value: Avengers Movie

Expected Output:

enter image description here

I know you can select elements. I've also seen this done before somewhere. However, I cannot find a resource that explains the identifiers used. I saw you could highlight it here but not insert.

littlecoder
  • 356
  • 2
  • 15
  • Why not just dynamically link the search result directly? – XLIME Jan 15 '21 at 17:14
  • I have a long list of items and I want to save myself the trouble of searching/copy/pasting all the results. Essentially automating the process. – littlecoder Jan 15 '21 at 17:30

1 Answers1

1

Perhaps there's something I'm missing, but I'd populate the search link.

<a href="https://www.amazon.com/s?k=YOUR+SEARCH+VALUE">

Like previously mentioned, you can even populate the value to whatever you'd like using some javascript. For example:

You have an anchor with an id containing what you want to search.

<a id="star+wars">My Link</a>

We can use javascript to populate the search URL with your search term, then add it to the anchor using setAttribute

let yourLink = document.getElementById("star+wars");
let searchID = yourLink.id;

yourLink.setAttribute("href", "https://www.amazon.com/s?k=" + searchID);

JSFiddle: https://jsfiddle.net/L5afroh1/

XLIME
  • 185
  • 6