2

I am building a react app and I am trying to make get request using axios, I am trying to access imdb page like :-

https://www.imdb.com/find?q=Tom%20Hanks

But when I call the axios then it is showing

AxiosError {message: 'Network Error', name: 'AxiosError', code: 'ERR_NETWORK', config: {…}, request: XMLHttpRequest, …} code: "ERR_NETWORK" config: {transitional: {…}, transformRequest: Array(1), transformResponse: Array(1), timeout: 0, adapter: ƒ, …} message: "Network Error" name: "AxiosError" request: XMLHttpRequest {data: undefined, onreadystatechange: null, readyState: 4, timeout: 0, withCredentials: false, …} response: XMLHttpRequest {data: undefined, onreadystatechange: null, readyState: 4, timeout: 0, withCredentials: false, …} [[Prototype]]: Error

But When I try to access localhost using axios then it is working fine But not working with imdb

then I tried accessing imdb with python requests then it is showing 200 SUCCESS.

I have tried many times But it is showing that error everytime.

App.js

class App extends React.Component {
    componentDidMount() {
           axios.get('https://www.imdb.com/find?q=Tom%20Hanks').then(res => {
             console.log(res)
          }).catch(err => {console.log(err)})
    }

    render() {
      return(<div>Good Luck</div>)
   }
}

Any help would be much Appreciated.

ded
  • 21
  • 1
  • You cannot send a request to a third-party website from a browsers. You should read about [CORS](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS) – Idrizi.A May 31 '22 at 17:26
  • @Enve, Thanks for suggesstion. How can I set `CORS` with axios ? – ded May 31 '22 at 17:31
  • You can't, unless you own imdb.com. You cannot send a request to IMDB from a users browser, it's a security issue. Please read the article I sent above. – Idrizi.A May 31 '22 at 17:33
  • Can I send with server, I meant by `python-requests` ? As you said, "can't with browser" – ded May 31 '22 at 17:37
  • This should help you with CORS and react frontends : https://www.npmjs.com/package/cors-anywhere – DooMGuy096 May 31 '22 at 17:39
  • @DooMGuy096, Just five minutes, I am trying – ded May 31 '22 at 17:42
  • Yes you can, you can make a python page that takes a parameter for example: `localhost/fetchRequest?url=imdb.com\/find?q=Tom%20Hanks` which fetches the content of the `url` and returns it to you. However imdb is likely not going to like that and if it detects a bot scraping its content it will block your IP address. – Idrizi.A May 31 '22 at 17:44
  • @DooMGuy096, It is working but it is not showing full html and it is really difficult and a little bit Odd for extracting element – ded May 31 '22 at 17:51
  • @ded — It's a website not an API. Use the API. https://developer.imdb.com/ – Quentin May 31 '22 at 20:12
  • Another good movie API : https://developers.themoviedb.org/3 – DooMGuy096 Jun 01 '22 at 13:26

0 Answers0