I am trying to scrape text from a news article - I am doing this as follows:
library(rvest)
url <- "https://www.bbc.com/future/article/20220823-how-auckland-worlds-most-spongy-city-tackles-floods"
final = url %>%
read_html() %>%
html_elements(".article__body-content p") %>%
html_text()
This seems to have worked, but I am trying to combine the results of this code into a single object. For example, the current results look like this:
[1] "Tangled mats of muddy vegetation line the footpaths of Underwood Park, a narrow stripe of green winding along a creek beneath the small volcanic cone of Ōwairaka (Mt Albert) in Auckland, New Zealand. In the water, clumps of sticks and the occasional plastic bag are marooned on protruding rocks and branches."
[2] "A winter storm swept through the city overnight, dropping heavy rain, and Te Auaunga (Oakley Creek), one of the city’s longest urban streams, has overflowed its banks."
[3] "\"But that’s supposed to happen,\" says Julie Fairey, chair of the Puketāpapa local board, who is showing me around Underwood and the neighbouring Walmsley Park."
I would like to make a single object of this text - for example (remove all " "):
final <- "Tangled mats of muddy vegetation line the footpaths of Underwood Park, a narrow stripe of green winding along a creek beneath the small volcanic cone of Ōwairaka (Mt Albert) in Auckland, New Zealand. In the water, clumps of sticks and the occasional plastic bag are marooned on protruding rocks and branches.
A winter storm swept through the city overnight, dropping heavy rain, and Te Auaunga (Oakley Creek), one of the city’s longest urban streams, has overflowed its banks.
But that’s supposed to happen, says Julie Fairey, chair of the Puketāpapa local board, who is showing me around Underwood and the neighbouring Walmsley Park."
When I inspect the results, I initially thought it was a list - but it's actually a character object. Had this been a list, I could have used the "unlist" command. But now I am not sure how to proceed.
Can someone please show me how to proceed?
Thanks!
The output from html_text is a vector of strings. We could join them as a single string with paste and collapse.
library(rvest)
library(magrittr)
final <- url %>%
read_html() %>%
html_elements(".article__body-content p") %>%
html_text() %>%
paste(collapse = "\n")
Now, we check the output
cat(final, sep = "\n")
Tangled mats of muddy vegetation line the footpaths of Underwood Park, a narrow stripe of green winding along a creek beneath the small volcanic cone of Ōwairaka (Mt Albert) in Auckland, New Zealand. In the water, clumps of sticks and the occasional plastic bag are marooned on protruding rocks and branches.
A winter storm swept through the city overnight, dropping heavy rain, and Te Auaunga (Oakley Creek), one of the city’s longest urban streams, has overflowed its banks.
"But that’s supposed to happen," says Julie Fairey, chair of the Puketāpapa local board, who is showing me around Underwood and the neighbouring Walmsley Park.
The connected parks are designed to collect excess stormwater, soak it up like a sponge, and slowly release it back into the creek. The debris left behind is evidence this "secret infrastructure" is working, Fairey says. The two parks are flanked on both sides by public housing developments. "This stuff is designed to flood so that the houses don’t," she says.
It wasn’t always this way, Fairey tells me, as we watch a black shag drying its wings on a rock. Less than a decade ago, the waterway was a concrete-lined culvert that ran through seldom-visited muddy fields. When it flooded, water sloshed into the surrounding suburbs. It collected engine oil, sediment and rubbish and sucked this unhealthy mixture out into the city’s famous harbour, rendering the beaches unsafe to swim.
But in 2016, work began to free Te Auaunga from rigid concrete, and restore it to a more natural, meandering shape. Its banks are now lush with native vegetation like harakeke (flax) and tī kouka (cabbage trees), as well as reeds, ferns and other filtering wetland plants.
The changes have increased this part of the city’s ability to absorb excess rainfall, an attribute sometimes called “sponginess”. Auckland was recently named the most spongy global city in a report by multinational architecture and design firm Arup, thanks to its geography, soil type, and urban design – but experts warn it may not lead the pack for long.
As climate change intensifies extreme weather events worldwide, what can other cities learn from Auckland's successes – and failures?
The connected parks around Te Auaunga creek in Auckland are designed to soak up excess stormwater like a sponge (Credit: Kate Evans)
....
I have a paragraph of text and I need to add two hyperlinks inside the text.
We can't break this out and I can't seem to figure what commands to add.
Example:
full text:
'It is a period of civil wars in the galaxy. A brave alliance of underground freedom fighters has challenged the tyranny and oppression of the awesome GALACTIC EMPIRE. --> should be a hyperlink to galactic#empire.com
Striking from a fortress hidden among the billion stars of the galaxy, rebel spaceships have won their first victory in a battle with the powerful Imperial Starfleet. The EMPIRE fears that another defeat could bring a thousand more solar systems into the rebellion, and Imperial control over the galaxy would be lost forever.
To crush the rebellion once and for all, the EMPIRE - should click to empire.com is constructing a sinister new battle station. Powerful enough to destroy an entire planet, its completion spells certain doom for the champions of freedom.'
Use Placeholders in the text box to separate the text and add Actions to the two placeholders that you need to add links to.
Create the text box.
Click in the text box to type and then right click Create Placeholder.
Click on the Expression (Fx) button of the Value box. Add your text inside quotes after an equals sign.
="Your text here"
Click OK to get back to the properties. Click on HTML to allow HTML code and OK again.
Click in the text box again two or three times to get the cursor to the right of your last text placeholder, then right-click and Add Placeholder again.
Add the text again. ="Empire" Ok. Click on HTML. Now go to the Action and add the email link mailTo:galactic#empire.com.
Repeat the steps for the other text and link.
You'll end up with a single text box with multiple text placeholders. You can add color for the links if desired.
When it runs, it will show the text with links.
You can use the < br > tags to separate the paragraphs.
I'm currently having a small problem with getting containers to work properly in inform7. I've created a bed, which is marked as an enterable container. When the scene begins, the player is started out in the bed, and that appears to work ok. You can leave the container just fine. BUT, you can't re-enter the container. If I try to enter/get in/go inside the bed I get a message saying "you can't go that way" and I don't understand why. I'm quite new so there's probably something super simple that I'm missing here. Any ideas? Thanks so much!
Here's my code:
A Warm Cabin is a room. "A one room cabin with a fireplace on the south wall. There's a single window, frosted over from the cold."
Coming to is a scene. Coming to begins when Unconscious ends.
When coming to begins:
move the player to the double bed;
try waking up;
continue the action.
The Double Bed is a container. The double bed is in a warm cabin. The double bed is enterable and fixed in place. The description of the double bed is "A double bed strewn with soft, botanically-embroidered quilts and over-fluffed pillows. . . It's quite cozy."
Instead of entering the double bed: try going inside.
I have to do this repeatedly, so I was wondering if there was a working around....
here is a set of amenities for an apartment, they have to be transferred to a larger list containing those amenities by clicking off multiple choice cirlces. Is there away to edit the script to do it all at once>
example
accessible
air conditioning
dishwasher
garage
hardwood floors
parking
patio / balcony
gym
in unit laundry
cats allowed
dogs allowed
pet friendly
basketball court
bathtub
bbq/grill
bike storage
business center
carpet
ceiling fan
clubhouse
game room
granite counters
microwave
oven
package receiving
playground
pool table
range
refrigerator
stainless steel
walk in closets
I think you want to just checkmark all of the checkboxes on the amenities list so something like this will work:
$('div.whitelist-searchable-amenity input[type=checkbox]').each(function(){
$(this).prop('checked', true);
});
https://jsfiddle.net/r62qgou3/
Edit:
I am not sure of what you mean by "copying text to script" but I modified the script to check if the values that you are looking for are within the document. This should search the values of the checkboxes and then you can use your own script to "copy" the value elsewhere. Just add more values to the array if you need more keywords.
x = [
"accessible",
"air conditioning",
"dishwasher",
"garage",
];
$('div.whitelist-searchable-amenity input[type=checkbox]').each(function(){
if(x.indexOf(this.value) > -1)
{
alert("copy here");
}
});
I’ve been facing problem to retrieve HTML response from server and show it in UITextView ( i am using REST Api).
I wanted to send that again to remote server with modification of HTML string.
I’ve little bit idea about NSAttributedString and NSMutableString
Here is an Example String that I want to get it from server and display to UITextView and send it back to server after some operation.
<b>Soaking time</b>: 3 hours <br>
<b>Preparation time:</b> 15 mins <br>
<b>Fermenting time:</b> 8 hours <br>
<span><b>Cooking time:</b> 45 mins<br><br></span>
1. Soak the urad dal (split black lentils) and fenugreek seeds (methi) together in water for 3 hours and drain. <br>
2. Soak the parboiled rice in water for 3 hours and drain. <br>
3. Blend urad dal and fenugreek seeds together in a mixer till smooth and frothy (add water little by little as required) remove and keep aside. <br>
4. Blend the rice in a mixer till smooth. Remove and keep aside. <br>
5. Combine the urad dal paste and rice paste together in a bowl and keep aside to ferment overnight. <br>
6. Once the batter is fermented, add salt to the batter and mix well. <br>
7. Put spoonfuls of the batter into greased idli moulds and steam for 10 to 12 minutes. <br>
8. Serve at room temperature. <br>
I stuck here with current scenario as above.. Any help will be really appreciated.Thanks