How to get Nokogiri to scrape text from span in Ruby
Date : March 29 2020, 07:55 AM
hope this fix your issue In this case we need to find the second span after the span class="heading", and inside the div class="app-settings" - I'm being a bit general but not too much. I'm using search instead of at to retrieve the two spans and get the second one: # Gets the 2 span elements under <div class='app-settings'>.
res = html.search('#gaz-content-body .app-settings span')
# Use .text to get the contents of the 2nd element.
res[1].text.strip
# => "xxxxxxxx"
res = html.at("#gaz-content-body .app-settings span:nth-child(2)")
res.text.strip
# => "xxxxxxxx"
|
scrape <span> tag text using BeautifulSoup has no text attribute
Tag : python , By : user134570
Date : March 29 2020, 07:55 AM
To fix this issue As the error message clearly suggests, that's because findAll() returns ResultSet which doesn't have attribute text. You need to iterate through the result, or using list comprehension : for post in post_list:
print [span.text for span in post.findAll("span" , {"itemprop" : "name"})]
for post in post_list:
print post.find("span" , {"itemprop" : "name"}).text
|
JSOUP scrape html text from p and span
Tag : java , By : cheese_doodle
Date : March 29 2020, 07:55 AM
wish of those help Assuming that you want to get the paragraph of verse 1, you can do it using: :has(selector) to get only elements that contain elements matching the selector Then use as selector span.v:containsOwn(1) to indicate that you want a span of class v whose text contains 1. And finally use ownText() to get the text of the element itself not the text of its children too, otherwise if you want both use text(). String className = "v";
int verse = 1;
Element p = doc.select(String.format("p:has(span.%s:containsOwn(%d))", className, verse))
.first();
System.out.println(p.ownText());
Een psalm van David. De HEERE is mijn Herder, mij zal niets ontbreken.
StringBuilder sb = new StringBuilder();
Elements paragraphs = doc.select("p:has(span.v)");
for (Element p : paragraphs) {
sb.append(p.ownText() + "\n");
}
System.out.println(sb);
Een psalm van David. De HEERE is mijn Herder, mij zal niets ontbreken.
Hij doet mij nederliggen in grazige weiden; Hij voert mij zachtjes aan zeer stille wateren.
Hij verkwikt mijn ziel; Hij leidt mij in het spoor der gerechtigheid, om Zijns Naams wil.
|
How to python Scrape text in span class
Date : March 29 2020, 07:55 AM
help you fix your problem So I'm making a bitcoin checker practice and I'm having trouble scraping data because the data I want is in a span class and I don't know how to retrieve the data. , You just have to search for the right tag and class - from bs4 import BeautifulSoup
html_text = """
<span class="MarketInfo_market-num_1lAXs"> 11,511.31 USD </span>
"""
html = BeautifulSoup(html_text, "lxml")
spans = html.find_all('span', {'class': 'MarketInfo_market-num_1lAXs'})
for span in spans:
print(span.text.replace('USD', '').strip())
import requests
import json
url = 'https://api.gdax.com/products/BTC-USD/trades'
res = requests.get(url)
json_res = json.loads(res.text)
print(json_res[0]['price'])
|
Scrape a span text from multiple span elements of same name within a p tag in a website
Date : March 29 2020, 07:55 AM
this will help What you can do is find the tag that has the text 'Gross:'. Then, once it finds that tag, tell it to go find the next tag (which is the value amount), and get that text.from bs4 import BeautifulSoup as BS
html = '''<p class="sort-num_votes-visible">
<span class="text-muted">Votes:</span>
<span name="nv" data-value="93122">93,122</span>
<span class="ghost">|</span>
<span class="text-muted">Gross:</span>
<span name="nv" data-value="69,645,701">$69.65M</span>
</p>'''
soup = BS(html, 'html.parser')
gross_value = soup.find('span', text='Gross:').find_next('span').text
print (gross_value)
$69.65M
gross_value = soup.find('span', text='Gross:').find_next('span')['data-value']
print (gross_value)
69,645,701
gross_value = int(soup.find('span', text='Gross:').find_next('span')['data-value'].replace(',', ''))
print (gross_value)
69645701
|