Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not returning anything on certain websites #37

Open
eatanga-git opened this issue Jul 7, 2022 · 0 comments
Open

Not returning anything on certain websites #37

eatanga-git opened this issue Jul 7, 2022 · 0 comments

Comments

@eatanga-git
Copy link

eatanga-git commented Jul 7, 2022

It seems like certain websites or elements don't return anything?

This worked:

const [isLoading, setLoading] = useState(true);
const [data, setData] = useState("");

  useEffect(() => { 
  
   fetch('https://en.wikipedia.org/wiki/Nirvana_(band)')
    .then(response => response.text())
    .then(result => new JSSoup(result, false))
    .then(f=>(f.findAll('span','mw-headline')[1]))
    .then((t => t.getText()))
    .then(f => setData(f))
    .catch(function(error) {
      setData('There has been a problem with your fetch operation: ' + error.message);
       // ADD THIS THROW error
        throw error;
      }).finally(() => setLoading(false));

    },[])

    return(
      <Text>{data}</Text>
    )

But this did NOT work:

 const [isLoading, setLoading] = useState(true);
 const [data, setData] = useState("");

  useEffect(() => {
  
   fetch('https://www.google.com/search?q=sony')
    .then(response => response.text())
    .then(result => new JSSoup(result, false))
    .then(f=>(f.findAll('h2', 'LC20lb MBeuO DKV0Md')[1]))
    .then((t => t.getText()))
    .then(f => setData(f))
    .catch(function(error) {
      setData('There has been a problem with your fetch operation: ' + error.message);
       // ADD THIS THROW error
        throw error;
      }).finally(() => setLoading(false));

    },[])

    return(
      <Text>{data}</Text>
    )

I received a "[Unhandled promise rejection: TypeError: undefined is not an object (evaluating 't.getText')]" error for the 2nd code example.
Why is this the case?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant