This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
writer.Write([]string{ | |
productName, | |
stars, | |
price, | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func main() { | |
fileName := "amazon_products.csv" | |
file, err := os.Create(fileName) | |
if err != nil { | |
log.Fatalf("Could not create %s", fileName) | |
} | |
defer file.Close() | |
writer := csv.NewWriter(file) | |
defer writer.Flush() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
proxySwitcher, err := proxy.RoundRobinProxySwitcher("socks5://188.226.141.127:1080", "socks5://67.205.132.241:1080") | |
if err != nil { | |
log.Fatal(err) | |
} | |
c.SetProxyFunc(proxySwitcher) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
c.Limit(&colly.LimitRule{ | |
RandomDelay: 2 * time.Second, | |
Parallelism: 4, | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func main() { | |
c := colly.NewCollector( | |
colly.Async(true), | |
) | |
// ... | |
c.Wait() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for i := 1; i <= 20; i++ { | |
fullURL := fmt.Sprintf("https://www.amazon.com/s?k=nintendo+switch&page=%d", i) | |
c.Visit(fullURL) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ( | |
"fmt" | |
"github.com/gocolly/colly" | |
"github.com/icrowley/fake" | |
"github.com/mottet-dev/medium-go-colly-basics/utils" | |
) | |
func main() { | |
c := colly.NewCollector() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"github.com/gocolly/colly" | |
"github.com/mottet-dev/medium-go-colly-basics/utils" | |
) | |
func main() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package utils | |
import "regexp" | |
func FormatPrice(price *string) { | |
r := regexp.MustCompile(`\$(\d+(\.\d+)?).*$`) | |
newPrices := r.FindStringSubmatch(*price) | |
if len(newPrices) > 1 { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"github.com/gocolly/colly" | |
) | |
func main() { | |
c := colly.NewCollector() |