Reputation: 427
how i can get any link/page title using react
Supposed i have a link Product , i want to get <title>A High Performance High Quality 4 Wheeler Quad Bike Atv For Kids And Adult 125cc 250cc 4x4 Atv Loncin - Buy Atv Loncin 250cc 4x4,Atv Car For Kids,High Quality Atv Product on Alibaba.com</title>
this title.
so i get only "A High Performance High Quality 4 Wheeler Quad Bike Atv For Kids And Adult 125cc 250cc 4x4 Atv Loncin - Buy Atv Loncin 250cc 4x4,Atv Car For Kids,High Quality Atv Product on Alibaba.com"
Upvotes: 0
Views: 1121
Reputation: 186
Well, I guess I would start by getting the html from that product page and then navigating that html using normal getElementsByClassName or querySelector kind of methods. You might need to parse that HTML response first, but I would Imagine it would look something like this (assuming you use axios):
axios.get(`https://whatever.store/product-one`)
.then(res => {
const title = res.getElementById('id-of-element').title
//this.setState({ title: title}) or whatever you plan to do next
})
.catch(err => { console.log(err)})
Upvotes: 1