I'm attempting to create a scraper broken into two classes. One being a backend that will scrap a value from a website & return it to the front end, where for now it'll be printed. My problem is I'm stuck when it comes to getting a value defined outside a tag. I.e. <div class="temp">13</div>
Here is my backend so far, it takes a url in the get function in the event I want to add more classes that use it in the future
const PORT = 8000
const axios = require('axios')
const cheerio = require('cheerio')
const express = require('express')
const app = express()
const cors = require('cors')
const url = require("url");
app.use(cors())
app.get('/temp/:url1', (req, res) => {
axios(url1)
.then(response => {
const html = response.data
const $ = cheerio.load(html)
const value = []
*stuck here*
}).catch(err => console.log(err))
})
app.listen(PORT, () => console.log(`server running on PORT ${PORT}`))
Here is my first app. It's only calling fetch and printing the values
url1 = 'https://www.walmart.com/ip/Hind-Boys-Active-Shirts-Shorts-and-Jogger-Pants-8-Piece-Outfit-Set-Sizes-4-16/952146762?athcpid=952146762&athpgid=AthenaHomepageDesktop__gm__-1.0&athcgid=null&athznid=SeasonalCampaigns_d396fb61-c3c0-46db-a4d9-aaf34191b39f_items&athieid=null&athstid=CS020&athguid=kZNrXnatcjxcgUvbKkvbwYMT4bwAapwfOaos&athancid=null&athena=true&athbdg=L1400'
//(in this instance, the value I'm attempting to get is the "Now 24.99" portion)
fetch('http://localhost:8000/bids/' + url1)
.then(response => {return response.json()})
.then(data => {
console.log(data)
})
.catch(err => console.log(err))
To make it easier here is the HTML from the url
<span itemprop="price" aria-hidden="false">Now $24.97</span>
Via Active questions tagged javascript - Stack Overflow https://ift.tt/NAEJMCL
Comments
Post a Comment