Home > OS >  Printing 2 statements on the same line
Printing 2 statements on the same line

Time:01-20

I've successfully made a scraper that scrapes all 109 pages of the iPhone section on eBay.

The problem is that I need them to print on the same line. This is what it currently looks likepicture

package main

import (
    "fmt"
    "github.com/gocolly/colly"
)

func main() {
    c := colly.NewCollector(colly.UserAgent("Mozilla/5.0 (X11; Linux x86_64; rv:108.0) Gecko/20100101 Firefox/108.0"))

    c.OnHTML(".s-item__title", func(element *colly.HTMLElement) {
        element.ChildAttr("heading", "role")
        fmt.Println(element.Text)
    })

    c.OnHTML(".s-item__price", func(element *colly.HTMLElement) {
        fmt.Println(element.Text)
    })

    c.Visit("https://www.ebay.com/sch/i.html?_from=R40&_nkw=iPhone&_sacat=0&_pgn=1")
}

It's not even possible to navigate around this information. Can someone show me how I can get the Title along with the price on the same line?

I thought about renaming the element but it didn't work.

I would use printf or println, but then it just prints everything together.

CodePudding user response:

The fmt.Println() includes '\n' at the end. ln means new line. You can use fmt.PrintF() to format output however you want, it doesn't force a new line, if this is your issue.

CodePudding user response:

Try using fmt.Print instead of fmt.Println

  • Related