Click here to Skip to main content
15,918,003 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
This is my code:
JavaScript
let header = new Headers({
        "User-Agent": "My User-Agent",
});

fetch("url", {
    method: 'GET',
    withCredentials: true,
    crossorigin: true,
    headers: header,
}).then((res) => {
    return res.text();
}).then((result) => {
    console.log(result);
}).catch((err) => {
    console.log(err);
});


What I have tried:

I am trying to fetch Amazon product details (product name, image, price, etc.) to my website.

but I can't do that.

Please help me.
Posted
Updated 23-Jan-23 21:48pm

1 solution

Don;t do it in Javascript - do it in the backend, using whatever language your site is coded in.
Most backend languages have HTML processor addons: for VB / C# that would be the HTML Agility Pack, for Python it's BeautifulSoup, and so on.

These make working with HTML a whole load easier!

But ... and it's a big but ... scraping sites means frequent problems because sites change, and even a tiny change in the site backend code can make a massive change to the HTML it generates and that means your scraper doesn't work anymore. And the first sign you will get that this has happened is that your potential customers don't stay on your site long, which is really hard to measure or detect!

A much better approach is normally to use an API, and Amazon do provide a vendor API which may do what you want - but since we have no idea why you are doing this, we can't tell ...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900