cheerio

How to access DOM using Node.js?

◇◆丶佛笑我妖孽 提交于 2021-02-18 00:57:26
问题 I have an editor.html that contains generatePNG function: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Diagram</title> <script type="text/javascript" src="lib/jquery-1.8.1.js"></script> // <!-- I use many resources --> <script></script> <script> function generatePNG (oViewer) { var oImageOptions = { includeDecoratorLayers: false, replaceImageURL: true }; var d = new Date(); var h = d.getHours(); var m = d.getMinutes(); var s = d.getSeconds(); var sFileName = "diagram" + h

How to access DOM using Node.js?

谁说胖子不能爱 提交于 2021-02-18 00:55:36
问题 I have an editor.html that contains generatePNG function: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Diagram</title> <script type="text/javascript" src="lib/jquery-1.8.1.js"></script> // <!-- I use many resources --> <script></script> <script> function generatePNG (oViewer) { var oImageOptions = { includeDecoratorLayers: false, replaceImageURL: true }; var d = new Date(); var h = d.getHours(); var m = d.getMinutes(); var s = d.getSeconds(); var sFileName = "diagram" + h

Extracting text tags in order - How can this be done?

大城市里の小女人 提交于 2021-02-11 17:18:33
问题 I am trying to find all the text along with the parent tag in the HTML. In the example below, the variable named html has the sample HTML where I try to extract the tags and the text. This works fine and as expected gives out the tags with the text Here I have used cheerio to traverse DOM. cheerio works exactly same as jquery . const cheerio = require("cheerio"); const html = ` <html> <head></head> <body> <p> Regular bail is the legal procedure through which a court can direct release of

Extracting text tags in order - How can this be done?

故事扮演 提交于 2021-02-11 17:08:38
问题 I am trying to find all the text along with the parent tag in the HTML. In the example below, the variable named html has the sample HTML where I try to extract the tags and the text. This works fine and as expected gives out the tags with the text Here I have used cheerio to traverse DOM. cheerio works exactly same as jquery . const cheerio = require("cheerio"); const html = ` <html> <head></head> <body> <p> Regular bail is the legal procedure through which a court can direct release of

Extracting text tags in order - How can this be done?

风格不统一 提交于 2021-02-11 17:07:43
问题 I am trying to find all the text along with the parent tag in the HTML. In the example below, the variable named html has the sample HTML where I try to extract the tags and the text. This works fine and as expected gives out the tags with the text Here I have used cheerio to traverse DOM. cheerio works exactly same as jquery . const cheerio = require("cheerio"); const html = ` <html> <head></head> <body> <p> Regular bail is the legal procedure through which a court can direct release of

Node.js + Cheerio : Request inside a loop

血红的双手。 提交于 2021-02-07 10:45:25
问题 I'm using cheerio, request and Node.js. When I run the script below, it outputs names in a wrong order. I believe that it's caused by asynchronous nature of it, how can I make it work in the "right" order? Do I need to use a sync package or is there a way to change it in a way so it'll work in a sync way? app.get('/returned', function (req, res) { for (var y = 0; y < 10; y++) { var url = "http://example.com" + y + "/person.html"; request(url, function (err, resp, body) { $ = cheerio.load(body

Cheerio, axios, reactjs to web scrape a table off a webpage returning empty list

非 Y 不嫁゛ 提交于 2021-01-29 08:53:50
问题 Trying to scrape this table off this website: https://www.investing.com/commodities/real-time-futures But for some reason when I try to get the data, I keep getting an empty list. This is what I'm doing to get the data and parse it: componentDidMount() { axios.get(`https://www.investing.com/commodities/real-time-futures`) .then(response => { if(response.status === 200) { const html = response.data; const $ = cheerio.load(html); let data = []; $('#cross_rate_1 tr').each((i, elem) => { data

target text after br tag using cheerio

喜欢而已 提交于 2021-01-29 05:46:31
问题 I'm practicing creating an API by scraping using cheerio. I'm scraping from this fairly convoluted site: http://www.vegasinsider.com/nfl/odds/las-vegas/ I'm trying to target the text after these <br> tags within the anchor tag in this <td> element: <td class="viCellBg1 cellTextNorm cellBorderL1 center_text nowrap" width="56"> <a class="cellTextNorm" href="/nfl/odds/las-vegas/line-movement/packers-@- bears.cfm/date/9-05-19/time/2020#BT" target="_blank">  <br>46u-10<br>-3½ -10 </a> </td> The

How to fix '$(…).click is not a function' in Node/Cheerio

人盡茶涼 提交于 2021-01-28 11:40:34
问题 I am writing an application in node.js that will navigate to a website, click a button on the website, and then extract certain pieces of data from the website. All is going well except for the button-clicking aspect. I cannot seem to simulate a button click. I'm extremely new at this, so I'd appreciate any suggestions y'all have! Sadly I've scoured the internet looking for a solution to this issue and have been unable to find one. I have used .click() and .bind('click, ...) in a .js file

scrape website using nodejs cheerio deep nested element tags

社会主义新天地 提交于 2021-01-28 06:50:12
问题 I'm trying to scrape text from a website but can't seem to extract anything. below is the structure and code. My code: const rp = require("request-promise"); const $ = require("cheerio"); const url = "xx"; rp(url) .then(function(html) { //success! let token = "ce-bodytext"; console.log($(token, response).length); console.log($(token, html)).text; }) .catch(function(err) { console.log(JSON.stringify(err)); }); While I just need the text, there was no id to the tag. Also, I was hoping ce