Skip to content

Not returning anything on certain websites #37

Description

@erick-atanga

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?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions