SIM
SIM

Reputation: 22440

Can't manipulate parsed string

I've created a parser to get address and zip code from a webpage using python. My parser is running specklessly. The result is coming in two lines. However, I'm very weak in manipulating string. So, if anybody helps me on this, I would be very grateful. Thanks.

Here is the script:

import requests ; from lxml import html

link = "http://www.greenthumbnyc.org/gardensearch.html#map-canvas"

def green_thumb(base_link):
    response = requests.get(base_link)
    tree = html.fromstring(response.text)
    title = tree.cssselect(".garden-info p")[0].text_content().replace("More information","")
    print(title)

green_thumb(link)

Results I'm having:

138th Street Community Garden (El Girasol)
624-638 East 138th Street

Results I would like to have:

138th Street Community Garden (El Girasol) 624-638 East 138th Street

Upvotes: 0

Views: 45

Answers (1)

Paul Wilson
Paul Wilson

Reputation: 68

Try adding .replace("\n","")

title = tree.cssselect(".garden-info p")[0].text_content().replace("More information","").replace("\n","")

Hope this helps.

Upvotes: 1

Related Questions