cheerio

Finding alternate selectors from contains

拈花ヽ惹草 提交于 2020-01-17 05:37:15
问题 I have a list of elements obtained through the contains selector. Let's say I want to know how to access a person's name on a profile page. I can test my own profile with my own name. let name = $(':contains(jamie)'); I'd like to store a selector based on the above results that could be used to retrieve the name from any profile. Without walking the DOM and calculating a selector, is there another way to get a (single or list) selector to each element that comes out of the contains query? 回答1

Finding alternate selectors from contains

泄露秘密 提交于 2020-01-17 05:37:11
问题 I have a list of elements obtained through the contains selector. Let's say I want to know how to access a person's name on a profile page. I can test my own profile with my own name. let name = $(':contains(jamie)'); I'd like to store a selector based on the above results that could be used to retrieve the name from any profile. Without walking the DOM and calculating a selector, is there another way to get a (single or list) selector to each element that comes out of the contains query? 回答1

How with use node.js get information from this tag that in page source - {{= flyingStatus(it.m_status) }}?

对着背影说爱祢 提交于 2020-01-06 08:26:15
问题 If I look page source, I see "unusual" attribute value: class = "bma-fly flying {{= flyingStatus(it.m_status) }} Usually for me this is: class = "value" After loaded page, if I use button "Inspect", I see: class = "bma-fly flying flying-won-team2 flying-past" Now question, how get information with use Node.js from this "unusual" attribute value, if I use cheerio (jquery), but see nothing??? For example: request(link, function(err, resp, html) { if (!err){ const $ = cheerio.load(html); let

Adding Cheerio.js to an Angular 6 project?

非 Y 不嫁゛ 提交于 2020-01-04 18:17:25
问题 I created a brand-new Angular 6 project and installed Cheerio.js: npm install cheerio Once Cheerio.js was installed, I figured all I had to do to add it to my project was to import it and add it to the NgModule imports: import { BrowserModule } from '@angular/platform-browser'; import { NgModule } from '@angular/core'; import { AppComponent } from './app.component'; import * as cheerio from 'cheerio'; @NgModule({ declarations: [ AppComponent ], imports: [ BrowserModule, cheerio ], providers:

Can I load a local html file with the cheerio package in node.js?

杀马特。学长 韩版系。学妹 提交于 2019-12-31 10:32:11
问题 I have a few html files on my harddrive that I'd like to use jquery on to extract data from. Is this possible to do using cheerio? I've tried giving cheerio the local path but it doesn't work. One idea I had would be to create a web server in node, read from the html file, and then pipe it to cheerio through the server - would this 回答1: The input is an html string, so you need to read the html content yourself: var fs = require('fs'); cheerio.load(fs.readFileSync('path/to/file.html')); 回答2: A

extracting text from html elements with cheerio

早过忘川 提交于 2019-12-25 07:19:07
问题 Using cheerio, $ is defined as cheerio object, I am trying to get the text from some elements which have a class forceWordWrap in a html. The following cheerio selectors are returning nothing. What am I doing wrong? Thanks const text = $("td[class='forceWordWrap']"); const date = text.eq(0).text(); const title = text.eq(1).text(); const description = text.eq(2).text(); <p/> <form name="his" method="post" action="/a/b.axp"> <input type="hidden" name="action" value="accept"/> <table width="100%

Unable to fetch results using callback

余生颓废 提交于 2019-12-25 00:52:46
问题 I've written a script in node using two different functions getPosts() and getContent() supplying callback within them in order to print the result calling a standalone function getResult() . The selectors defined within my script is flawless. However, when I execute my script, It prints nothing. It doesn't throw any error either. I tried to mimic the logic provied by Neil in this post. How can I make it a go? I've written so far: var request = require('request'); var cheerio = require(

Trying to extract HTML between two style elements with cheerio

情到浓时终转凉″ 提交于 2019-12-24 18:28:09
问题 I'm scraping an HTML page but I'm trying to get one section of the page. There are no classes, id's or anything super useful I can plug into Cheerio I feel like (I'm new to this, so I know my ignorance plays a part). The code looks like this. <b> Here's some text I don't want</b> <b> More text I don't want</b> <hr style="width:90%; padding: 0> <b> text I want </b> <b> text I want </b> <b> text I want </b> <b> text I want </b> <hr style="width:90%; padding: 0> <b> Here's some text I don't want

Cheerio NPM trying to obtain values for img src in nodeJS

不想你离开。 提交于 2019-12-24 09:59:19
问题 Image of current source: Here Current code: let imageArr = [] $('.plink image').each(function(){ let image = $(this).attr('src') imageArr.push(image) }) console.log(imageArr) Log nothing , why so? 回答1: Don't has tag image , it is img . Use .plink.image img instead of .plink image . const $ = cheerio.load(body, { xmlMode: true // to load noscript }) let imageArr = [] $('.plink.image img').each(function(a, b) { let image = $(this).attr('src') if (image && !image.match(/white.jpg$/)) { // remove

Nodejs Scraper isn't moving to next page(s)

感情迁移 提交于 2019-12-24 05:48:35
问题 Hey guys this is a follow on from my other question, i have created a Nodejs Scraper that doesnt seem to want to go through the pages, it stays on the first. my source code is below const rp = require('request-promise'); const request = require('request'); const otcsv = require('objects-to-csv'); const cheerio = require('cheerio'); //URL To scrape const baseURL = 'xxx'; const searchURL = 'xxxx'; //scrape info const getCompanies = async () => { // Pagination test for (let index = 1; index <=