
Security News
Crates.io Implements Trusted Publishing Support
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
github.com/go-some/crawler
crowl 서비스의 크롤러를 구현합니다.
go get -u github.com/gocolly/colly/...
go get go.mongodb.org/mongo-driver
go get -u github.com/go-some/crawler
type Reuters struct {
}
articleCollector
의 리시버를 통해 저장합니다.News
struct 형식에 맞게 mongoDB에 저장되며 WriteDocs
(writer.go)함수에서 그 기능을 수행합니다.func (rc *Reuters) Run(wtr DocsWriter) {
// Instantiate default NewCollector
c := colly.NewCollector(
colly.MaxDepth(3),
// Visit only finance and businessnews section
colly.URLFilters(
regexp.MustCompile("https://www\\.reuters\\.com/finance"),
regexp.MustCompile("https://www\\.reuters\\.com/news/archive/businessnews.+"),
),
colly.DisallowedURLFilters(
regexp.MustCompile("https://www\\.reuters\\.com/finance/.+"),
),
)
c.AllowURLRevisit = false
// Create another collector to scrape each news article
articleCollector := colly.NewCollector()
c.OnHTML("a[href]", func(e *colly.HTMLElement) {
/* crawl all href links recursively */
link := e.Request.AbsoluteURL(e.Attr("href"))
//if the link is article page, crawl using articleCollector
//else, visit the link until MaxDepth
if strings.Index(link, "reuters.com/article") != -1 {
articleCollector.Visit(link)
} else {
e.Request.Visit(link) //e.Request.Visit을 이용해야 MaxDepth 처리가 된다.
}
})
articleCollector.OnHTML("div.StandardArticle_inner-container", func(e *colly.HTMLElement) {
/* Read article page and save to mongoDB
- 최종적으로 우리가 크롤하고자 하는 기사 페이지 (leaf node)
*/
doc := News{
Title: e.ChildText(".ArticleHeader_headline"),
Body: e.ChildText("div.StandardArticleBody_body"),
Time: e.ChildText(".ArticleHeader_date"),
Url: e.Request.URL.String(),
Origin: "Reuters",
}
cnt, err := wtr.WriteDocs([]News{doc})
if err != nil {
fmt.Println(err)
} else {
fmt.Println(cnt, "docs saved")
}
})
c.Visit("https://www.reuters.com/finance")
}
FAQs
Unknown package
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
Research
/Security News
Undocumented protestware found in 28 npm packages disrupts UI for Russian-language users visiting Russian and Belarusian domains.
Research
/Security News
North Korean threat actors deploy 67 malicious npm packages using the newly discovered XORIndex malware loader.