How to use QueryTitle method of main Package

Best Syzkaller code snippet using main.QueryTitle

spider.go

Source:spider.go Github

copy

Full Screen

1package main2import (3 "bufio"4 "fmt"5 "log"6 "net/http"7 "os"8 "strings"9 "github.com/PuerkitoBio/goquery"10 "github.com/magiconair/properties"11)12type queryCondition struct {13 queryString string14 queryTitle string15 queryTarget string16 queryDetail string17 queryOutput bool18 queryOutParnt bool19 queryDrilldwn bool20 subQuery []queryCondition21}22var propFileName string = "spider.conf"23var fetchCount int = 024var queryConditions []queryCondition25var includeEmpty bool = false26var outputUrl bool = false27var checkstopDepth bool = false28var checkstopCount bool = false29var stopDepth int = 330var stopCount int = 10031var outputFile bool = true32var outputFileName string = "result.txt"33var logDocument bool = false34func main() {35 prop := properties.MustLoadFile(propFileName, properties.UTF8)36 startMethod := prop.MustGetString("start-method")37 startUrl := prop.MustGetString("start-url")38 startFile := prop.MustGetString("start-file")39 checkstopDepth = prop.MustGetBool("check-stop-by-depth")40 checkstopCount = prop.MustGetBool("check-stop-by-count")41 stopDepth = prop.MustGetInt("stop-depth")42 stopCount = prop.MustGetInt("stop-count")43 includeEmpty = prop.MustGetBool("include-empty-value")44 outputUrl = prop.MustGetBool("output-with-url")45 outputFile = prop.MustGetBool("output-to-file")46 outputFileName = prop.MustGetString("output-file-name")47 logDocument = prop.MustGetBool("log-document")48 // 預先準備要抓的 query string49 prepareQueryConditions(prop);50 // start crawler51 if strings.ToLower(startMethod) == "url" {52 // start from one url53 crawl(startUrl, 0)54 } else if strings.ToLower(startMethod) == "file" {55 // open file to get all urls56 file, err := os.Open(startFile)57 if err != nil {58 log.Fatalf("[ERROR] Error in open URL file: %s", err)59 }60 fileScanner := bufio.NewScanner(file)61 for fileScanner.Scan() { crawl(fileScanner.Text(), 0) }62 if err := fileScanner.Err(); err != nil {63 log.Fatalf("[ERROR] Error in read URL file: %s", err)64 }65 file.Close()66 }67}68func crawl(url string, depth int) {69 log.Println("target: ", url)70 // load dom object from url71 doc, success := loadUrl(url)72 if !success {73 log.Println("[ERROR] Not a valid document.")74 return75 }76 fetchCount = fetchCount + 177 // show all document for debug78 if logDocument { log.Println(doc.Html()) }79 // Find target DOM items80 for _, thisQry := range queryConditions {81 doc.Find(thisQry.queryString).Each(func(idx int, s *goquery.Selection) {82 var value string = ""83 switch thisQry.queryTarget {84 case "TEXT":85 value = strings.TrimSpace(s.Text())86 case "ATTR":87 val, exist := s.Attr(thisQry.queryDetail)88 if exist { value = strings.TrimSpace(val) }89 }90 // prepare output string and output91 queryResult := ""92 if outputUrl {93 queryResult = fmt.Sprintf("[%s] %s: %s", url, thisQry.queryTitle, value)94 } else {95 queryResult = fmt.Sprintf("%s: %s", thisQry.queryTitle, value)96 }97 if thisQry.queryOutput && (includeEmpty || (value != "")) {98 // output to log99 log.Println("[OUTPUT]", queryResult)100 // output to file101 outputToFile(queryResult + "\r\n")102 }103 if thisQry.subQuery != nil {104 for _, thisSubQry := range thisQry.subQuery {105 s.Find(thisSubQry.queryString).Each(func(idx int, ss *goquery.Selection) {106 subVal := ""107 switch thisSubQry.queryTarget {108 case "TEXT":109 subVal = strings.TrimSpace(ss.Text())110 case "ATTR":111 val, exist := ss.Attr(thisSubQry.queryDetail)112 if exist { subVal = strings.TrimSpace(val) }113 }114 115 // prepare output string and output116 querySubResult := ""117 if outputUrl {118 if thisSubQry.queryOutParnt {119 querySubResult = fmt.Sprintf("[%s][%s] %s: %s", url, value, thisSubQry.queryTitle, subVal)120 } else {121 querySubResult = fmt.Sprintf("[%s] %s: %s", url, thisSubQry.queryTitle, subVal)122 }123 } else {124 if thisSubQry.queryOutParnt {125 querySubResult = fmt.Sprintf("[%s] %s: %s", value, thisSubQry.queryTitle, subVal)126 } else {127 querySubResult = fmt.Sprintf("%s: %s", thisSubQry.queryTitle, subVal)128 }129 }130 if thisSubQry.queryOutput && (includeEmpty || (subVal != "")) {131 // output to log132 log.Println("[OUTPUT]", querySubResult)133 // output to file134 outputToFile(querySubResult + "\r\n")135 }136 })137 // go drill-down url138 if meetStopCritiron(depth) && thisSubQry.queryDrilldwn { crawl(value, depth+1) }139 }140 }141 // go drill-down url142 if meetStopCritiron(depth) && thisQry.queryDrilldwn { crawl(value, depth+1) }143 })144 }145}146func loadUrl(url string)(doc *goquery.Document, success bool) {147 // get HTML content148 res, err := http.Get(url)149 if err != nil {150 log.Println("[ERROR] Not a valid url")151 return nil, false152 }153 defer res.Body.Close()154 if res.StatusCode != 200 {155 log.Println("[ERROR] status code error: ", res.StatusCode, res.Status)156 return nil, false157 }158 159 // Load the HTML document160 doctmp, err := goquery.NewDocumentFromReader(res.Body)161 if err != nil {162 log.Println("[ERROR] Not a valid document.")163 return nil, false164 }165 return doctmp, true166}167// read query-conditions in properties168func prepareQueryConditions(prop *properties.Properties) {169 // get other conditions170 queryCount := prop.MustGetInt("query-string-count")171 for i := 1; i <= queryCount; i++ {172 // query parameters173 queryString := prop.MustGetString(fmt.Sprintf("query-string-%d", i))174 queryTitle := prop.MustGetString(fmt.Sprintf("query-string-%d-title", i))175 queryTarget := prop.MustGetString(fmt.Sprintf("query-string-%d-target", i))176 queryDrilldwn := prop.MustGetBool( fmt.Sprintf("query-string-%d-drilldown", i))177 queryOutput := prop.MustGetBool( fmt.Sprintf("query-string-%d-output", i))178 querySub := prop.MustGetBool( fmt.Sprintf("query-string-%d-sub-query", i))179 thisQueryCond := parseSingleCondition(180 queryString, queryTitle, queryTarget,181 queryDrilldwn, queryOutput, false)182 if querySub {183 subQryCount := prop.MustGetInt(fmt.Sprintf("query-string-%d-sub-count", i))184 for j := 1; j <= subQryCount; j++ {185 // query parameters186 subQryString := prop.MustGetString(fmt.Sprintf("query-string-%d-sub-%d-string", i, j))187 subQryTitle := prop.MustGetString(fmt.Sprintf("query-string-%d-sub-%d-title", i, j))188 subQryTarget := prop.MustGetString(fmt.Sprintf("query-string-%d-sub-%d-target", i, j))189 subQryDrilldwn := prop.MustGetBool( fmt.Sprintf("query-string-%d-sub-%d-drilldown", i, j))190 subQryOutput := prop.MustGetBool( fmt.Sprintf("query-string-%d-sub-%d-output", i, j))191 subQryOutParnt := prop.MustGetBool( fmt.Sprintf("query-string-%d-sub-%d-output-with-parent", i, j))192 thisSubQueryCond := parseSingleCondition(193 subQryString, subQryTitle, subQryTarget,194 subQryDrilldwn, subQryOutput, subQryOutParnt)195 thisQueryCond.subQuery = append(thisQueryCond.subQuery, thisSubQueryCond)196 }197 }198 queryConditions = append(queryConditions, thisQueryCond)199 }200}201func parseSingleCondition(qStr string, qTtl string, qTar string, qExp bool, qOut bool, qOutParnt bool)(qry queryCondition) {202 //thisQueryCond := new(queryCondition)203 var thisQueryCond queryCondition204 thisQueryCond.queryString = strings.TrimSpace(qStr)205 thisQueryCond.queryTitle = strings.TrimSpace(qTtl)206 queryTargetParts := strings.Split(strings.TrimSpace(qTar), ":")207 switch len(queryTargetParts) {208 case 1:209 thisQueryCond.queryTarget = strings.ToUpper(queryTargetParts[0])210 thisQueryCond.queryDetail = ""211 case 2:212 thisQueryCond.queryTarget = strings.ToUpper(queryTargetParts[0])213 thisQueryCond.queryDetail = queryTargetParts[1]214 }215 thisQueryCond.queryDrilldwn = qExp216 thisQueryCond.queryOutput = qOut217 thisQueryCond.queryOutParnt = qOutParnt218 return thisQueryCond219}220// check if stop spider221func meetStopCritiron(currDepth int)(isStop bool) {222 stop := false223 stop = stop || (checkstopDepth && (currDepth < stopDepth))224 stop = stop || (checkstopCount && (fetchCount < stopCount))225 return stop226}227// output to result file228func outputToFile(outputString string) {229 if outputFile {230 f, err := os.OpenFile(outputFileName, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)231 if err != nil { log.Println("[ERROR] Error in open output file: ", err) }232 defer f.Close()233 if _, err := f.WriteString(outputString); err != nil {234 log.Println("[ERROR] Error in write to output file: ", err)235 }236 }237}238/*239func queryHandler(url string, thisQry queryCondition, s *goquery.Selection)(json string) {240 // output of this query241 resultJson := fmt.Sprintf("{\r\n\turl: %s\r\n", url)242 thisVal := ""243 switch thisQry.queryTarget {244 case "TEXT":245 thisVal = s.Text()246 case "ATTR":247 val, exist := s.Attr(thisQry.queryDetail)248 if exist { thisVal = val }249 }250 if includeEmpty || (thisVal != "") {251 resultJson += fmt.Sprintf("\t%s: %s\r\n", thisQry.queryTitle, thisVal)252 }253 return resultJson254}255*/...

Full Screen

Full Screen

service.go

Source:service.go Github

copy

Full Screen

...13)14// Service interface exposed to clients15type QueryService interface {16 QueryAuthor(string, int, int) (Authors, error)17 QueryTitle(string, string, string, int, int) (Titles, error)18}19////////////////////////20// Actual service21type queryService struct{}22//////////23// METHODS on queryService24// Constants for URLs in openlibrary25const BASE_AUTHOR_URL = "https://openlibrary.org/search/authors?q="26const BASE_TITLE_URL = "https://openlibrary.org/search?"27const ROOT_URL = "https://openlibrary.org"28const WORKS_BASE_URL = "https://openlibrary.org"29// for images30const ROOT_AUTHOR_IMAGE = "https://covers.openlibrary.org/a/olid/"31const ROOT_COVER_IMAGE = "https://covers.openlibrary.org/b/"32////////////////33// Query Authors34//35// returns:36// Authors37// error38func (theService queryService) QueryAuthor(authorName string, offset int, limit int) (Authors, error) {39 fmt.Println(" ")40 fmt.Println("-- QueryAuthor --")41 authorName = url.QueryEscape(authorName)42 queryUrl := BASE_AUTHOR_URL + authorName43 fmt.Println("looking for:", queryUrl)44 // Make request to openlibrary45 body, err := makeRequest(queryUrl)46 if err != nil {47 fmt.Println("Unable to make request to openlibrary for authors: ", err)48 return Authors{}, err49 }50 // parse Authors response51 openlibraryAuthors := OpenLibraryAuthors{}52 jsonErr := json.Unmarshal(body, &openlibraryAuthors)53 if jsonErr != nil {54 fmt.Println("Unable to unmarshall response from openlibrary for author query:", jsonErr)55 return Authors{}, err56 }57 // data to return58 datum := make([]Author, 0, 0)59 // Convert openlibrary response into our structure60 for _, current := range openlibraryAuthors.Data {61 // Parse this author62 // Update subjects to not have a few entries we don't want63 newSubjects := make([]string, 0, len(current.Subjects))64 for _, subject := range current.Subjects {65 if (!strings.Contains(subject, "Accessible book")) &&66 (!strings.Contains(subject, "Protected DAISY")) {67 // add to subjects68 newSubjects = append(newSubjects, subject)69 }70 }71 // images72 smallImage := ROOT_AUTHOR_IMAGE + current.OlKey + "-S.jpg"73 mediumImage := ROOT_AUTHOR_IMAGE + current.OlKey + "-M.jpg"74 largeImage := ROOT_AUTHOR_IMAGE + current.OlKey + "-L.jpg"75 // Create author to return76 newAuthor := Author{77 BirthDate: current.BirthDate,78 Name: current.Name,79 OlKey: current.OlKey,80 Subjects: newSubjects,81 ImageSmall: smallImage,82 ImageMedium: mediumImage,83 ImageLarge: largeImage,84 }85 // Add to data86 datum = append(datum, newAuthor)87 }88 ////////////////////89 // Update the offset/limit90 // Get the total number of rows91 realNumberRows := len(openlibraryAuthors.Data)92 // fix offset93 if (offset > realNumberRows) || (offset < 0) {94 offset = 095 }96 // fix limit97 if limit <= 0 {98 limit = 2099 }100 // determine slice of datum to use101 whereToEnd := offset + limit102 if whereToEnd > realNumberRows {103 whereToEnd = realNumberRows104 }105 datum = datum[offset:whereToEnd]106 authorsToReturn := Authors{107 Offset: offset,108 Limit: len(datum),109 Total: realNumberRows,110 Data: datum,111 }112 return authorsToReturn, nil113}114////////////////115// Query Titles116//117// returns:118// Titles119// error120func (theService queryService) QueryTitle(authorName string, title string, isbn string, offset int, limit int) (Titles, error) {121 fmt.Println(" ")122 fmt.Println("-- QueryTitle --")123 // base url for titles124 queryUrl := BASE_TITLE_URL125 // string used in concating126 and := ""127 if len(title) > 0 {128 title = url.QueryEscape(title)129 queryUrl += and + "title=" + title130 and = "&"131 }132 if len(isbn) > 0 {133 isbn = url.QueryEscape(isbn)134 queryUrl += and + "isbn=" + isbn135 and = "&"136 }...

Full Screen

Full Screen

routes.go

Source:routes.go Github

copy

Full Screen

...9 router.GET("/qi/:id", QueryId)10 router.GET("/json/qi/:id", QueryIdAsJson)11 router.GET("/qg/:tag", QueryTag)12 router.GET("/g/:tag", QueryTag)13 router.GET("/qt/:title", QueryTitle)14 router.GET("/q/:query", Query)15 router.GET("/q/:query/l/:limit", Query)16 router.GET("/qg/:tag/q/:query", QueryTagAndWildCard)17 router.GET("/q/:query/qg/:tag", QueryTagAndWildCard)18 router.GET("/g/:tag/:query", QueryTagAndWildCard)19 router.GET("/qt/:title/q/:query", QueryTitleAndWildCard)20 router.GET("/q/:query/qt/:title", QueryTitleAndWildCard)21 router.GET("/show/:id", QueryId)22 router.GET("/new", WebNoteForm)23 router.GET("/edit/:id", WebNoteForm)24 router.GET("/del/:id", WebDeleteNote)25 router.GET("/js/:file", ServeJS)26 router.POST("/create", WebCreateNote)27 router.POST("/note/:id", WebUpdateNote)28 router.POST("/dup/:id", WebNoteDup)29 router.GET("/dup/:id", WebNoteDup)30}...

Full Screen

Full Screen

QueryTitle

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 for _, url := range os.Args[1:] {4 title, err := QueryTitle(url)5 if err != nil {6 fmt.Fprintf(os.Stderr, "QueryTitle: %v7 os.Exit(1)8 }9 fmt.Println(title)10 }11}12import (13func main() {14 for _, url := range os.Args[1:] {15 title, err := QueryTitle(url)16 if err != nil {17 fmt.Fprintf(os.Stderr, "QueryTitle: %v18 os.Exit(1)19 }20 fmt.Println(title)21 }22}23import (24func main() {25 for _, url := range os.Args[1:] {26 title, err := QueryTitle(url)27 if err != nil {28 fmt.Fprintf(os.Stderr, "QueryTitle: %v29 os.Exit(1)30 }31 fmt.Println(title)32 }33}34import (35func main() {36 for _, url := range os.Args[1:] {37 title, err := QueryTitle(url)38 if err != nil {39 fmt.Fprintf(os.Stderr, "QueryTitle: %v40 os.Exit(1)41 }42 fmt.Println(title)43 }44}45import (46func main() {47 for _, url := range os.Args[1:] {48 title, err := QueryTitle(url)49 if err != nil {

Full Screen

Full Screen

QueryTitle

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(QueryTitle())4}5import (6func main() {7 fmt.Println(QueryTitle())8}9import (10func main() {11 fmt.Println(QueryTitle())12}13import (14func main() {15 fmt.Println(QueryTitle())16}17import (18func main() {19 fmt.Println(QueryTitle())20}21import (22func main() {23 fmt.Println(QueryTitle())24}25import (26func main() {27 fmt.Println(QueryTitle())28}29import (30func main() {31 fmt.Println(QueryTitle())32}33import (34func main() {35 fmt.Println(QueryTitle())36}37import (38func main() {39 fmt.Println(QueryTitle())40}41import (42func main() {43 fmt.Println(QueryTitle())44}45import (46func main() {47 fmt.Println(QueryTitle())48}49import (50func main() {51 fmt.Println(QueryTitle())52}

Full Screen

Full Screen

QueryTitle

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 fmt.Println(QueryTitle())4}5func QueryTitle() string {6}

Full Screen

Full Screen

QueryTitle

Using AI Code Generation

copy

Full Screen

1import "./main"2func main() {3 main.QueryTitle("Go", "Go")4}5import "fmt"6func QueryTitle(title, author string) {7 fmt.Println(title, author)8}9In the code above, the main class is in the main package. The main package is imported using the dot operator. The dot operator indicates that the current directory is the path to the main package. The QueryTitle method is in the 2.go file. The QueryTitle method is in the main package. The main package is imported using the dot operator. The dot operator indicates that the current directory

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Syzkaller automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful