How to use Loop method of html Package

Best K6 code snippet using html.Loop

internal.go

Source:internal.go Github

copy

Full Screen

...15 var iconUrlLoRes, iconUrlHiRes string16 var iconUrls = []string{"", ""}17 var containerFound bool18 var containerTagNum int6419mainLoop:20 for {21 if openedTags < containerTagNum {22 // this means that we have exited the container without finding the target element,23 // so we will break the loop as this is an indication on a expected wrong structure from the parser.24 break mainLoop25 }26 tt := acTz.Next()27 totalTagsCounter++28 switch tt {29 case html.StartTagToken:30 t := acTz.Token()31 switch t.Data {32 case "div":33 openedTags++34 // skip non candidate tags to improve the speed35 if len(t.Attr) == 0 {36 continue mainLoop37 }38 for _, attr := range t.Attr {39 if attr.Key == "class" && attr.Val == "xSyT2c" {40 containerFound = true41 containerTagNum = openedTags42 continue mainLoop43 }44 }45 case "img":46 // <img> tags doesn't count against opened tags.47 if containerFound && openedTags == containerTagNum {48 /*// skip non candidate tags to improve the speed49 if len(t.Attr) < 5 {50 continue mainLoop51 }*/52 var tmpLoRes string53 var tmpHiRes string54 var signs int855 for _, attr := range t.Attr {56 switch {57 case attr.Key == "class" && attr.Val == "T75of sHb2Xb":58 signs++59 case attr.Key == "itemprop" && attr.Val == "image":60 signs++61 case attr.Key == "src" && attr.Val != "":62 signs++63 tmpLoRes = attr.Val64 case attr.Key == "srcset" && attr.Val != "":65 signs++66 tmpHiRes = attr.Val67 }68 }69 if signs == 4 {70 tmpHiRes, e := formatHiResImgUrl(tmpHiRes)71 if e != nil {72 return nil, e73 }74 iconUrlLoRes = tmpLoRes75 iconUrlHiRes = tmpHiRes76 break mainLoop77 }78 }79 default:80 // count even any tag that we might close in parsing.81 handleDefaultStartTagToken(t)82 }83 case html.SelfClosingTagToken:84 // try to parse the img tag if it's identified as SelfClosingTag.85 // it was already being identified as a StartTag, but now it stopped.86 t := acTz.Token()87 switch t.Data {88 case "img":89 // <img> tags doesn't count against opened tags.90 if containerFound && openedTags == containerTagNum {91 /*// skip non candidate tags to improve the speed92 if len(t.Attr) < 5 {93 continue mainLoop94 }*/95 var tmpLoRes string96 var tmpHiRes string97 var signs int898 for _, attr := range t.Attr {99 switch {100 case attr.Key == "class" && attr.Val == "T75of sHb2Xb":101 signs++102 case attr.Key == "itemprop" && attr.Val == "image":103 signs++104 case attr.Key == "src" && attr.Val != "":105 signs++106 tmpLoRes = attr.Val107 case attr.Key == "srcset" && attr.Val != "":108 signs++109 tmpHiRes = attr.Val110 }111 }112 if signs == 4 {113 tmpHiRes, e := formatHiResImgUrl(tmpHiRes)114 if e != nil {115 return nil, e116 }117 iconUrlLoRes = tmpLoRes118 iconUrlHiRes = tmpHiRes119 break mainLoop120 }121 }122 }123 case html.EndTagToken:124 handleDefaultEndTagToken(acTz.Token())125 case html.ErrorToken:126 break mainLoop127 }128 }129 if iconUrlLoRes == "" || iconUrlHiRes == "" {130 return nil, fmt.Errorf("couldn't extract the app icon urls")131 }132 iconUrls[0] = iconUrlLoRes133 iconUrls[1] = iconUrlHiRes134 return iconUrls, nil135}136func ExtractAppName(acTz *html.Tokenizer) (string, error) {137 var appName string138 var containerFound bool139 var innerContainerFound bool140 var containerTagNum int64141mainLoop:142 for {143 if openedTags < containerTagNum {144 break mainLoop145 }146 tt := acTz.Next()147 totalTagsCounter++148 switch tt {149 case html.StartTagToken:150 t := acTz.Token()151 switch t.Data {152 case "h1":153 openedTags++154 // skip non candidate tags to improve the speed155 if len(t.Attr) < 2 {156 continue mainLoop157 }158 var signs int8159 for _, attr := range t.Attr {160 switch {161 case attr.Key == "class" && attr.Val == "AHFaub":162 signs++163 case attr.Key == "itemprop" && attr.Val == "name":164 signs++165 }166 }167 if signs == 2 {168 containerFound = true169 containerTagNum = openedTags170 continue mainLoop171 }172 case "span":173 openedTags++174 if containerFound && openedTags > containerTagNum {175 // this is to checks if we have entered the span body or not,176 // to prevent taking any wrong text instead of the app name.177 innerContainerFound = true178 }179 default:180 // count even any tag that we might close in parsing.181 handleDefaultStartTagToken(t)182 }183 case html.TextToken:184 if innerContainerFound {185 t := acTz.Token()186 appName = t.Data187 break mainLoop188 }189 case html.EndTagToken:190 handleDefaultEndTagToken(acTz.Token())191 case html.ErrorToken:192 break mainLoop193 }194 }195 if appName == "" {196 return "", fmt.Errorf("couldn't extract the app name")197 }198 return appName, nil199}200// (devURL, devName, error)201func ExtractDevInfo(acTz *html.Tokenizer) (string, string, error) {202 var devName, devURL string203 var containerFound bool204 var containerTagNum int64205mainLoop:206 for {207 tt := acTz.Next()208 totalTagsCounter++209 switch tt {210 case html.StartTagToken:211 t := acTz.Token()212 switch t.Data {213 case "a":214 openedTags++215 // skip non candidate tags to improve the speed216 if len(t.Attr) < 2 {217 continue mainLoop218 }219 var signs int8220 var tmp string221 for _, attr := range t.Attr {222 switch {223 case attr.Key == "class" && attr.Val == "hrTbp R8zArc":224 signs++225 case attr.Key == "href" && strings.Contains(attr.Val, devPageUrlPrefix):226 signs++227 tmp = attr.Val228 }229 }230 if signs == 2 {231 devURL = tmp232 containerFound = true233 containerTagNum = openedTags234 }235 default:236 handleDefaultStartTagToken(t)237 }238 case html.TextToken:239 if containerFound && containerTagNum <= openedTags {240 t := acTz.Token()241 devName = t.Data242 break mainLoop243 }244 case html.EndTagToken:245 handleDefaultEndTagToken(acTz.Token())246 case html.ErrorToken:247 break mainLoop248 }249 }250 if devURL == "" || devName == "" {251 return "", "", fmt.Errorf("couldn't find the dev page url or the dev name")252 }253 devURL, e := updateDevUrl(devURL)254 if e != nil {255 return "", "", e256 }257 return devURL, devName, nil258}259// (catUrl, catName, err)260func ExtractCategoryInfo(acTz *html.Tokenizer) (string, string, error) {261 var catUrl, catName string262 var containerFound bool263 var containerTagNum int64264mainLoop:265 for {266 tt := acTz.Next()267 totalTagsCounter++268 switch tt {269 case html.StartTagToken:270 t := acTz.Token()271 switch t.Data {272 case "a":273 // count only the tags that we actually open.274 openedTags++275 // skip non candidate tags to improve the speed276 if len(t.Attr) < 3 {277 continue mainLoop278 }279 var signs int8280 var tmp string281 for _, attr := range t.Attr {282 switch {283 case attr.Key == "class" && attr.Val == "hrTbp R8zArc":284 signs++285 case attr.Key == "itemprop" && attr.Val == "genre":286 signs++287 case attr.Key == "href" && strings.Contains(attr.Val, catPageUrlPrefix):288 signs++289 tmp = attr.Val290 }291 }292 if signs == 3 {293 catUrl = tmp294 containerFound = true295 containerTagNum = openedTags296 }297 default:298 // count even any tag that we might close in parsing.299 handleDefaultStartTagToken(t)300 }301 case html.TextToken:302 // we can do this here(check for equality), as the text should be in the same level.303 if containerFound && containerTagNum == openedTags {304 t := acTz.Token()305 catName = t.Data306 break mainLoop307 }308 case html.EndTagToken:309 handleDefaultEndTagToken(acTz.Token())310 case html.ErrorToken:311 break mainLoop312 }313 }314 if catUrl == "" || catName == "" {315 return "", "", fmt.Errorf("couldn't find the category url or the category name")316 }317 catUrl, e := updateCatUrl(catUrl)318 if e != nil {319 return "", "", e320 }321 return catUrl, catName, nil322}323// (containsAds, inAppPurchase, error)324func ExtractInAppOffering(acTz *html.Tokenizer) (string, error) {325 var offeringString = ""326 var containerFound bool327 var containerTagNum int64328mainLoop:329 for {330 tt := acTz.Next()331 totalTagsCounter++332 switch tt {333 case html.StartTagToken:334 t := acTz.Token()335 switch t.Data {336 case "div":337 openedTags++338 // skip non candidate tags to improve the speed339 if len(t.Attr) == 0 {340 continue mainLoop341 }342 for _, attr := range t.Attr {343 switch {344 case attr.Key == "class" && attr.Val == "wE7q7b":345 // reaching this case means we passed the position without finding any offerings.346 break mainLoop347 case attr.Key == "class" && attr.Val == "bSIuKf":348 // this is the container we need.349 containerFound = true350 containerTagNum = openedTags351 }352 }353 default:354 // count even any tag that we might close in parsing355 handleDefaultStartTagToken(t)356 }357 case html.TextToken:358 // we can do this here(check for equality), as all the offering strings should be in the same level.359 if containerFound && containerTagNum == openedTags {360 t := acTz.Token()361 content := strings.TrimSpace(t.Data)362 if len(offeringString) == 0 {363 offeringString = content364 } else {365 offeringString += ", " + content366 }367 }368 case html.EndTagToken:369 handleDefaultEndTagToken(acTz.Token())370 case html.ErrorToken:371 break mainLoop372 }373 }374 if containerFound && offeringString == "" {375 return "", fmt.Errorf("the offering container is found, however we couldn't extract the data")376 } else {377 return offeringString, nil378 }379}380func ExtractPrice(acTz *html.Tokenizer) (string, error) {381 var price string382 var containerFound bool383 var containerTagNum int64384mainLoop:385 for {386 if openedTags < containerTagNum {387 break mainLoop388 }389 tt := acTz.Next()390 totalTagsCounter++391 switch tt {392 case html.StartTagToken:393 t := acTz.Token()394 switch t.Data {395 case "span":396 openedTags++397 // skip non candidate tags to improve the speed398 if len(t.Attr) < 2 {399 continue mainLoop400 }401 var signs int8402 for _, attr := range t.Attr {403 switch {404 case attr.Key == "itemprop" && attr.Val == "offers":405 fallthrough406 case attr.Key == "itemtype" && attr.Val == "https://schema.org/Offer":407 signs++408 }409 }410 if signs == 2 {411 containerFound = true412 containerTagNum = openedTags413 }414 case "meta":415 if containerFound && openedTags == containerTagNum {416 // skip non candidate tags to improve the speed417 /*if len(t.Attr) < 2 {418 continue mainLoop419 }*/420 var tmp string421 var signs int8422 for _, attr := range t.Attr {423 switch {424 case attr.Key == "itemprop" && attr.Val == "price":425 signs++426 case attr.Key == "content" && attr.Val != "":427 signs++428 tmp = attr.Val429 }430 }431 if signs == 2 {432 price = tmp433 break mainLoop434 }435 }436 default:437 handleDefaultStartTagToken(t)438 }439 case html.EndTagToken:440 handleDefaultEndTagToken(acTz.Token())441 case html.ErrorToken:442 break mainLoop443 }444 }445 if price == "" {446 return "", fmt.Errorf("couldn't find the app price")447 }448 return price, nil449}450func ExtractMediaUrls(acTz *html.Tokenizer) ([]string, []string, error) {451 var startImgUrl, videoUrl string452 var videoURLs = []string{"", ""}453 var imagesURLs = make([]string, 0, 30)454 var mediaContainerFound bool455 var mediaContainerTagNum int64456 var videoImgContainerFound bool457 var videoImgContainerTagNum int64458 var videoContainerFound bool459 var videoContainerTagNum int64460videoLoop:461 for {462 if openedTags < mediaContainerTagNum {463 break videoLoop464 }465 tt := acTz.Next()466 totalTagsCounter++467 switch tt {468 case html.StartTagToken:469 t := acTz.Token()470 switch t.Data {471 case "div":472 openedTags++473 // skip non candidate tags to improve the speed474 if len(t.Attr) < 1 {475 continue videoLoop476 }477 attrLoop:478 for _, attr := range t.Attr {479 switch {480 case attr.Key == "class" && attr.Val == "SgoUSc":481 // the container of all the media is found, containing the trailer video with its start screen,482 // and all the containers for the screenshots.483 mediaContainerFound = true484 mediaContainerTagNum = openedTags485 // break out of the attr loop, cause all these cases are mutually exclusive.486 break attrLoop487 case mediaContainerFound && attr.Key == "class" && attr.Val == "MSLVtf Q4vdJd":488 videoImgContainerFound = true489 videoImgContainerTagNum = openedTags490 break attrLoop491 case videoImgContainerFound && attr.Key == "class" && attr.Val == "TdqJUe":492 videoContainerFound = true493 videoContainerTagNum = openedTags494 break attrLoop495 }496 }497 case "img":498 if videoImgContainerFound && openedTags == videoImgContainerTagNum {499 // skip non candidate tags to improve the speed500 /*if len(t.Attr) < 2 {501 continue videoLoop502 }*/503 var tmp string504 var signs int8505 for _, attr := range t.Attr {506 switch {507 case attr.Key == "class" && attr.Val == "T75of DYfLw":508 signs++509 case attr.Key == "src" && attr.Val != "":510 signs++511 tmp = attr.Val512 }513 }514 if signs == 2 {515 startImgUrl = tmp516 }517 }518 case "button":519 openedTags++520 if videoContainerFound && openedTags == videoContainerTagNum+1 {521 // skip non candidate tags to improve the speed522 /*if len(t.Attr) < 2 {523 continue videoLoop524 }*/525 var tmp string526 var signs int8527 for _, attr := range t.Attr {528 switch {529 /*case attr.Key == "jscontroller" && attr.Val == "HnDLGf":530 signs++*/531 case attr.Key == "class" && attr.Val == "MMZjL lgooh ":532 signs++533 case attr.Key == "data-trailer-url" && attr.Val != "":534 signs++535 tmp = attr.Val536 }537 }538 if signs == 2 {539 videoUrl = tmp540 // we have found the video url already,541 // so, break from the video loop to the screenshots loop.542 break videoLoop543 }544 } else {545 // check if the video container hasn't been found and we have skipped to the screenshots directly.546 // skip non candidate tags to improve the speed547 /*if len(t.Attr) < 1 {548 continue videoLoop549 }*/550 for _, attr := range t.Attr {551 switch {552 case attr.Key == "class" && attr.Val == "Q4vdJd":553 // the button found is the container for a screenshot,554 // so, break from the video loop to the screenshots loop.555 break videoLoop556 }557 }558 }559 default:560 // count even any tag that we might close in parsing561 handleDefaultStartTagToken(t)562 }563 case html.SelfClosingTagToken:564 // try to parse the img tag if it's identified as SelfClosingTag.565 t := acTz.Token()566 switch t.Data {567 case "img":568 if videoImgContainerFound && openedTags == videoImgContainerTagNum {569 // skip non candidate tags to improve the speed570 /*if len(t.Attr) < 2 {571 continue videoLoop572 }*/573 var tmp string574 var signs int8575 for _, attr := range t.Attr {576 switch {577 case attr.Key == "class" && attr.Val == "T75of DYfLw":578 signs++579 case attr.Key == "src" && attr.Val != "":580 signs++581 tmp = attr.Val582 }583 }584 if signs == 2 {585 startImgUrl = tmp586 }587 }588 }589 case html.EndTagToken:590 handleDefaultEndTagToken(acTz.Token())591 case html.ErrorToken:592 break videoLoop593 }594 }595screenshotsLoop:596 for {597 // break the loop if we exit the target container tag598 if openedTags < mediaContainerTagNum || !mediaContainerFound {599 break screenshotsLoop600 }601 tt := acTz.Next()602 totalTagsCounter++603 switch tt {604 case html.StartTagToken, html.SelfClosingTagToken:605 t := acTz.Token()606 switch t.Data {607 case "img":608 // skip non candidate tags to improve the speed609 /*if len(t.Attr) < 5 {610 continue screenshotsLoop611 }*/612 var tmpSrc string613 var tmpSrcset string614 var signs int8615 for _, attr := range t.Attr {616 switch {617 case attr.Key == "src" && attr.Val != "":618 signs++619 tmpSrc = attr.Val620 case attr.Key == "srcset" && attr.Val != "":621 signs++622 tmpSrcset = attr.Val623 case attr.Key == "class" && attr.Val == "T75of DYfLw":624 signs++625 case attr.Key == "itemprop" && attr.Val == "image":626 signs++627 }628 }629 if signs == 4 {630 highRes, e := formatHiResImgUrl(tmpSrcset)631 if e != nil {632 highRes = tmpSrcset633 }634 imagesURLs = append(imagesURLs, tmpSrc, highRes)635 }636 default:637 if tt == html.StartTagToken {638 handleDefaultStartTagToken(t)639 }640 }641 case html.EndTagToken:642 handleDefaultEndTagToken(acTz.Token())643 case html.ErrorToken:644 break screenshotsLoop645 }646 }647 if mediaContainerFound {648 if videoImgContainerFound && (startImgUrl == "" || videoUrl == "") {649 return nil, nil, fmt.Errorf("the video container is found, " +650 "however, we couldn't extract the required urls")651 } else if !videoImgContainerFound {652 return nil, imagesURLs, nil653 } else {654 videoURLs[0] = startImgUrl655 videoURLs[1] = videoUrl656 return videoURLs, imagesURLs, nil657 }658 } else {659 return nil, nil, fmt.Errorf("the media container is not found")660 }661}662func ExtractDescription(acTz *html.Tokenizer) (string, error) {663 /*var descContainerFound bool664 var descContainerTagNum int64665 var desc = ""*/666 // the second method related vars667 var descContainerFound2 bool668 var descContainerTagNum2 int64669 var desc2 = ""670mainLoop:671 for {672 /*if openedTags < descContainerTagNum {673 break mainLoop674 }*/675 if openedTags < descContainerTagNum2 {676 break mainLoop677 }678 tt := acTz.Next()679 totalTagsCounter++680 switch tt {681 case html.StartTagToken:682 t := acTz.Token()683 switch t.Data {684 case "div":685 openedTags++686 if len(t.Attr) < 1 {687 continue mainLoop688 }689 for _, attr := range t.Attr {690 switch {691 /*case attr.Key == "class" && attr.Val == "W4P4ne ":692 // related to the first method.693 descContainerFound = true694 descContainerTagNum = openedTags695 break*/696 case attr.Key == "jsname" && attr.Val == "sngebd":697 // related to the second method.698 descContainerFound2 = true699 descContainerTagNum2 = openedTags700 break701 }702 }703 /*case "meta":704 // this is used as a first method to retrieve the description, which get it from the meta tag.705 if !descContainerFound || openedTags != descContainerTagNum || len(t.Attr) < 2 {706 continue mainLoop707 }708 var signs uint8709 var tmp string710 for _, attr := range t.Attr {711 switch {712 case attr.Key == "itemprop" && attr.Val == "description":713 signs++714 case attr.Key == "content" && attr.Val != "":715 signs++716 tmp = attr.Val717 }718 }719 if signs == 2 {720 desc = tmp721 break mainLoop722 }*/723 default:724 handleDefaultStartTagToken(t)725 }726 case html.TextToken:727 // this is used as a second method to retrieve the description, which gets it from the text tags.728 if descContainerFound2 && openedTags == descContainerTagNum2 {729 t := acTz.Token()730 desc2 += t.Data731 }732 case html.EndTagToken:733 handleDefaultEndTagToken(acTz.Token())734 case html.ErrorToken:735 break mainLoop736 }737 }738 /*if !descContainerFound {739 return "", fmt.Errorf("the description tag is not found")740 } else if desc == "" {741 return "", fmt.Errorf("the description tag is found however we couldn't extract the description text")742 } else {743 return desc, nil744 }*/745 if !descContainerFound2 {746 return "", fmt.Errorf("the description tag is not found")747 } else if desc2 == "" {748 return "", fmt.Errorf("the description tag is found however we couldn't extract the description text")749 } else {750 return desc2, nil751 }752}753func ExtractRatingInfo(acTz *html.Tokenizer) (string, string, error) {754 var ratingContainerFound bool755 var ratingContainerTagNum int64756 var ratingCountOuterContainerFound bool757 var ratingCountInnerContainerFound bool758 var ratingCountOuterContainerTagNum int64759 var ratingCountInnerContainerTagNum int64760 var rating string761 var ratingCount string762ratingLoop:763 for {764 if openedTags < ratingContainerTagNum {765 break ratingLoop766 }767 tt := acTz.Next()768 totalTagsCounter++769 switch tt {770 case html.StartTagToken:771 t := acTz.Token()772 switch t.Data {773 case "div":774 openedTags++775 if len(t.Attr) != 2 {776 continue ratingLoop777 }778 var signs uint8779 for _, attr := range t.Attr {780 switch {781 case attr.Key == "class" && attr.Val == "BHMmbe":782 signs++783 case attr.Key == "aria-label" && attr.Val != "":784 signs++785 }786 }787 if signs == 2 {788 ratingContainerFound = true789 ratingContainerTagNum = openedTags790 }791 default:792 handleDefaultStartTagToken(t)793 }794 case html.TextToken:795 if ratingContainerFound && openedTags == ratingContainerTagNum {796 rating = acTz.Token().Data797 break ratingLoop798 }799 case html.EndTagToken:800 handleDefaultEndTagToken(acTz.Token())801 case html.ErrorToken:802 break ratingLoop803 }804 }805ratingCountLoop:806 for {807 if openedTags < ratingCountOuterContainerTagNum {808 break ratingCountLoop809 }810 tt := acTz.Next()811 totalTagsCounter++812 switch tt {813 case html.StartTagToken:814 t := acTz.Token()815 switch t.Data {816 case "span":817 openedTags++818 if len(t.Attr) < 1 {819 continue ratingCountLoop820 }821 var signs uint8822 attrLoop:823 for _, attr := range t.Attr {824 switch {825 case attr.Key == "class" && attr.Val == "EymY4b":826 ratingCountOuterContainerFound = true827 ratingCountOuterContainerTagNum = openedTags828 break attrLoop829 case ratingCountOuterContainerFound && attr.Key == "class" && attr.Val == "":830 signs++831 case ratingCountOuterContainerFound && attr.Key == "aria-label" && attr.Val != "":832 signs++833 }834 }835 if signs == 2 && openedTags > ratingCountOuterContainerTagNum {836 ratingCountInnerContainerFound = true837 ratingCountInnerContainerTagNum = openedTags838 }839 default:840 handleDefaultStartTagToken(t)841 }842 case html.TextToken:843 if ratingCountInnerContainerFound && openedTags == ratingCountInnerContainerTagNum {844 ratingCount = acTz.Token().Data845 break ratingCountLoop846 }847 case html.EndTagToken:848 handleDefaultEndTagToken(acTz.Token())849 case html.ErrorToken:850 break ratingCountLoop851 }852 }853 if ratingContainerFound && rating == "" {854 return "", "", fmt.Errorf("the rating container is found, however we couldn't extract the rating")855 } else if !ratingContainerFound {856 return "", "", fmt.Errorf("the rating container is not found")857 }858 if ratingCountOuterContainerFound && rating == "" {859 return "", "", fmt.Errorf("the rating count container is found, however we couldn't extract the rating count")860 } else if !ratingCountOuterContainerFound {861 return "", "", fmt.Errorf("the rating count container is not found")862 }863 return rating, ratingCount, nil864}865func ExtractRatingHistogram(acTz *html.Tokenizer) (map[string]string, error) {866 var histogramContainerFound bool867 var histogramContainerTagNum int64868 var barNumContainerFound bool869 var histogram = make(map[string]string, 5)870 currentBar := ""871mainLoop:872 for {873 if openedTags < histogramContainerTagNum {874 break mainLoop875 }876 tt := acTz.Next()877 totalTagsCounter++878 switch tt {879 case html.StartTagToken:880 t := acTz.Token()881 switch t.Data {882 case "div":883 openedTags++884 if len(t.Attr) != 1 {885 continue mainLoop886 }887 for _, attr := range t.Attr {888 switch {889 case attr.Key == "class" && attr.Val == "VEF2C":890 histogramContainerFound = true891 histogramContainerTagNum = openedTags892 }893 }894 case "span":895 openedTags++896 if len(t.Attr) < 1 || !histogramContainerFound {897 continue mainLoop898 }899 var signs uint8900 var tmpValue string901 for _, attr := range t.Attr {902 switch {903 case attr.Key == "class" && attr.Val == "Gn2mNd":904 barNumContainerFound = true905 continue mainLoop906 case attr.Key == "style" && attr.Val != "":907 signs++908 tmpValue = attr.Val909 case attr.Key == "class" && strings.Contains(attr.Val, "L2o20d"):910 signs++911 /*case attr.Key == "title" && attr.Val != "":912 signs++913 tmpValue = attr.Val*/914 }915 if signs == 2 && currentBar != "" {916 histogram[currentBar] = tmpValue917 currentBar = ""918 if len(histogram) == 5 {919 break mainLoop920 }921 }922 }923 default:924 handleDefaultStartTagToken(t)925 }926 case html.TextToken:927 if barNumContainerFound && currentBar == "" {928 currentBar = acTz.Token().Data929 barNumContainerFound = false930 }931 case html.EndTagToken:932 handleDefaultEndTagToken(acTz.Token())933 case html.ErrorToken:934 break mainLoop935 }936 }937 if histogramContainerFound && len(histogram) == 5 {938 return histogram, nil939 } else if histogramContainerFound && len(histogram) != 5 {940 return nil, fmt.Errorf("the histogram container is found, however we couldn't extract the histogram data")941 } else {942 return nil, fmt.Errorf("the histogram container is not found")943 }944}945func ExtractWhatsNew(acTz *html.Tokenizer) (string, error) {946 var wnOuterContainerFound bool // whatsNewOuterContainer947 var wnOuterContainerTagNum int64948 var wnInnerContainerFound bool949 var wnInnerContainerTagNum int64950 var whatsNewDataFound bool951 var whatsNew string952mainLoop:953 for {954 if openedTags < wnOuterContainerTagNum {955 break mainLoop956 }957 tt := acTz.Next()958 totalTagsCounter++959 switch tt {960 case html.StartTagToken:961 t := acTz.Token()962 switch t.Data {963 case "c-wiz":964 openedTags++965 if len(t.Attr) < 4 {966 continue mainLoop967 }968 var signs uint8969 var tmp string970 for _, attr := range t.Attr {971 switch {972 case attr.Key == "jsrenderer" && attr.Val != "":973 tmp = attr.Val974 fallthrough975 case attr.Key == "jsshadow":976 fallthrough977 case attr.Key == "jsdata" && attr.Val != "":978 fallthrough979 case attr.Key == "jsmodel" && attr.Val == "hc6Ubd":980 signs++981 }982 }983 if signs == 4 {984 if tmp == "eG38Ge" {985 wnOuterContainerFound = true986 wnOuterContainerTagNum = openedTags987 } else if tmp == "HEOg8" {988 wnOuterContainerFound = false989 break mainLoop990 }991 }992 case "div":993 openedTags++994 if len(t.Attr) < 3 || !wnOuterContainerFound {995 continue mainLoop996 }997 var signs uint8998 for _, attr := range t.Attr {999 switch {1000 case attr.Key == "class" && attr.Val == "DWPxHb":1001 fallthrough1002 case attr.Key == "jsname" && attr.Val == "bN97Pc":1003 fallthrough1004 case attr.Key == "itemprop" && attr.Val == "description":1005 signs++1006 }1007 }1008 if signs == 3 {1009 wnInnerContainerFound = true1010 wnInnerContainerTagNum = openedTags1011 }1012 case "span":1013 openedTags++1014 if wnInnerContainerFound && openedTags == wnInnerContainerTagNum+1 && len(t.Attr) == 1 {1015 whatsNewDataFound = true1016 }1017 default:1018 handleDefaultStartTagToken(t)1019 }1020 case html.TextToken:1021 if whatsNewDataFound {1022 whatsNew = acTz.Token().Data1023 break mainLoop1024 // whatsNewDataFound = false1025 }1026 case html.EndTagToken:1027 handleDefaultEndTagToken(acTz.Token())1028 case html.ErrorToken:1029 break mainLoop1030 }1031 }1032 if wnInnerContainerFound && whatsNew == "" {1033 return "", fmt.Errorf("the whats new container is found, but we couldn't extract the data from it")1034 } else if whatsNew != "" {1035 return whatsNew, nil1036 } else {1037 return "", nil1038 }1039}1040// TODO, extractLastUpdated1041// TODO, extractSize1042// TODO, extractNumOfDownloads1043// TODO, extractAppVer...

Full Screen

Full Screen

callDriver.go

Source:callDriver.go Github

copy

Full Screen

1package handler2import (3 "encoding/json"4 "fmt"5 "net/http"6 "strconv"7 "strings"8 "time"9 "../config"10 "../model"11 tb "../toolbox"12 "github.com/astaxie/beego/logs"13)14type paramsType struct {15 Nick string `json:"nick"`16 Msg string `json:"msg"`17}18type responseType struct {19 Status int `json:"status"`20 Msg string `json:"msg"`21}22type CmdType struct {23 Key string `json:"key"`24 Value string `json:"value"`25}26const myName = "BlackCarDriver"27// CallDriver应用请求全部经过这里28func CallDriverHandler(w http.ResponseWriter, r *http.Request) {29 // logs.Debug("callDriver url=%v", r.URL)30 url := strings.Trim(fmt.Sprintf("%s", r.URL.Path), "/")31 switch url {32 case "callDriver":33 CallDriverHtml(w, r)34 case "callDriver/sendMessage":35 callDriverReceiveMsg(w, r)36 case "callDriver/getHistory":37 callDriverGetChatHistroy(w, r)38 case "callDriver/boss":39 callDriverBossHtml(w, r)40 case "callDriver/boss/getAll":41 callDriverGetAllChat(w, r)42 case "callDriver/boss/reply":43 callDriverBossReply(w, r)44 case "callDriver/boss/control":45 callDriverSetMail(w, r)46 default:47 NotFoundHandler(w, r)48 }49}50func CallDriverHtml(w http.ResponseWriter, r *http.Request) {51 RecordRequest(r, "🚓")52 assetsHandler(w, "res/html/callDriverIndex.html")53}54// 接受来自callDriver应用的消息,保存到数据库并发送通知邮件55func callDriverReceiveMsg(w http.ResponseWriter, r *http.Request) {56 var req paramsType57 var resp responseType58 var err error59 ip, _ := tb.GetIpAndPort(r)60 for loop := true; loop; loop = false {61 // 解析参数62 err = tb.MustQueryFromRequest(r, &req)63 if err != nil {64 logs.Error("Parse request fail: err=%v request=%v", r)65 break66 }67 req.Nick = strings.TrimSpace(req.Nick)68 req.Msg = strings.TrimSpace(req.Msg)69 // 参数检查70 if len(req.Nick) < 2 || len(req.Msg) < 1 {71 resp.Status = -172 resp.Msg = "nick or message is too short"73 break74 }75 if req.Nick == myName {76 resp.Status = -177 resp.Msg = "Sorry, you can't use it nick..."78 break79 }80 // 保存聊天记录81 err = model.InsertCallDriverMessage(req.Nick, myName, req.Msg, ip)82 if err != nil {83 logs.Error("Save to history fail: err=%v", err)84 break85 }86 // 发送邮箱通知87 if config.ServerConfig.IsTest || !sendCallDriverEmail {88 logs.Info("Skip send email: isTest=%s sendCallDriverEmail=%v", config.ServerConfig.IsTest, sendCallDriverEmail)89 break90 }91 err = tb.SendToMySelf(req.Nick, req.Msg)92 if err != nil {93 logs.Error("Send mail fail: err=%v req=%+v", err, req)94 break95 }96 logs.Info("Send mail success")97 }98 logs.Info("hendle new message result: req=%+v err=%v", req, err)99 if err != nil {100 resp.Status = -1101 resp.Msg = fmt.Sprint(err)102 } else {103 resp.Status = 0104 }105 bytes, _ := json.Marshal(resp)106 fmt.Fprintf(w, "%s", bytes)107}108// 查询聊天记录109func callDriverGetChatHistroy(w http.ResponseWriter, r *http.Request) {110 type reqType struct {111 Nick string `json:"nick"`112 }113 type respType struct {114 Status int `json:"status"` // 当有新消息时,status=1115 Msg string `json:"msg"`116 ChatHtml string `json:"chatHtml"`117 }118 var req reqType119 var resp respType120 var history []model.CallDriverChat121 var err error122 for loop := true; loop; loop = false {123 // 解析参数124 err = tb.MustQueryFromRequest(r, &req)125 if err != nil {126 logs.Error("Parse request fail: err=%v request=%v", r)127 break128 }129 req.Nick = strings.TrimSpace(req.Nick)130 // 参数检查131 if len(req.Nick) < 2 {132 resp.Status = -1133 resp.Msg = "nick or message is too short"134 break135 }136 if req.Nick == myName {137 resp.Status = -1138 resp.Msg = "Sorry, you can't use it nick..."139 break140 }141 // 查询记录142 history, err = model.FindCallDriverMessage(req.Nick, 10)143 if err != nil || history == nil {144 logs.Error("get history fail: err=%v len=%v", err, len(history))145 break146 }147 // 生成聊条记录html代码148 divHtml := ""149 resp.Status = 0150 for idx := len(history) - 1; idx >= 0; idx-- {151 v := history[idx]152 if v.Status == 0 && v.From != req.Nick {153 logs.Info("add new message remark")154 resp.Status = 1155 }156 tstr := time.Unix(v.TimeStamp, 0).Format("01-02 15:04")157 className := "msgNick1"158 if v.From != req.Nick {159 className = "msgNick2"160 }161 divHtml += fmt.Sprintf(`<p class="msgTime">--------------------[ %s ]--------------------</p>162 <p class="%s">%s: <span class="msgText">%s</span></p>163 `, tstr, className, v.From, v.Message)164 }165 resp.Msg = divHtml166 }167 logs.Debug("get histroy result: req=%v err=%v", req, err)168 if err != nil {169 resp.Status = -1170 resp.Msg = fmt.Sprint(err)171 }172 bytes, _ := json.Marshal(resp)173 fmt.Fprintf(w, "%s", bytes)174}175//================ Boss专用,需要IP白名单权限 =========================176// Boss页面177func callDriverBossHtml(w http.ResponseWriter, r *http.Request) {178 if !config.ServerConfig.IsTest && !IpMonitor.IsInWhiteList(r) {179 w.WriteHeader(http.StatusNotAcceptable)180 return181 }182 assetsHandler(w, "res/html/callDriverBoss.html")183}184// Boss回复消息185func callDriverBossReply(w http.ResponseWriter, r *http.Request) {186 if !config.ServerConfig.IsTest && !IpMonitor.IsInWhiteList(r) {187 w.WriteHeader(http.StatusNotAcceptable)188 return189 }190 var req paramsType191 var resp responseType192 var err error193 ip, _ := tb.GetIpAndPort(r)194 for loop := true; loop; loop = false {195 // 解析参数196 err = tb.MustQueryFromRequest(r, &req)197 if err != nil {198 logs.Error("Parse request fail: err=%v request=%v", r)199 break200 }201 req.Nick = strings.TrimSpace(req.Nick)202 req.Msg = strings.TrimSpace(req.Msg)203 // 参数检查204 if len(req.Nick) < 2 || len(req.Msg) < 1 {205 resp.Status = -1206 resp.Msg = "nick or message is too short"207 }208 // 保存聊天记录209 err = model.InsertCallDriverMessage(myName, req.Nick, req.Msg, ip)210 if err != nil {211 logs.Error("Save to history fail: %v", err)212 break213 }214 logs.Info("reply success")215 }216 if err != nil {217 resp.Status = -1218 resp.Msg = fmt.Sprint(err)219 } else {220 resp.Status = 0221 }222 bytes, _ := json.Marshal(resp)223 fmt.Fprintf(w, "%s", bytes)224}225// Boss查看消息226func callDriverGetAllChat(w http.ResponseWriter, r *http.Request) {227 if !config.ServerConfig.IsTest && !IpMonitor.IsInWhiteList(r) {228 w.WriteHeader(http.StatusNotAcceptable)229 return230 }231 type respType struct {232 Status int `json:"status"`233 Msg string `json:"msg"`234 ChatHtml string `json:"chatHtml"`235 }236 var resp respType237 var history []model.CallDriverChat238 var err error239 for loop := true; loop; loop = false {240 // 查询记录241 history, err = model.FindAllCallDriverMessage()242 if err != nil || history == nil {243 logs.Error("get history fail: err=%v len=%v", err, len(history))244 break245 }246 // 生成聊条记录html代码247 divHtml := ""248 resp.Status = 0249 for idx := len(history) - 1; idx >= 0; idx-- {250 v := history[idx]251 tstr := time.Unix(v.TimeStamp, 0).Format("01-02 15:04")252 className := "msgNick1"253 if v.From != myName {254 className = "msgNick2"255 }256 divHtml += fmt.Sprintf(`<p class="msgTime">--------------------[ %s ]--------------------</p>257 <p class="%s">%s: <span class="msgText">%s</span></p>258 `, tstr, className, v.From, v.Message)259 }260 resp.Msg = divHtml261 }262 logs.Debug("get histroy result: err=%v", err)263 if err != nil {264 resp.Status = -1265 resp.Msg = fmt.Sprint(err)266 }267 bytes, _ := json.Marshal(resp)268 fmt.Fprintf(w, "%s", bytes)269}270// 其他相关控制271func callDriverSetMail(w http.ResponseWriter, r *http.Request) {272 if !config.ServerConfig.IsTest && !IpMonitor.IsInWhiteList(r) {273 w.WriteHeader(http.StatusNotAcceptable)274 return275 }276 var req CmdType277 var err error278 var resp responseType279 for loop := true; loop; loop = false {280 // 解析参数281 err = tb.MustQueryFromRequest(r, &req)282 if err != nil {283 logs.Error("Parse request fail: err=%v request=%v", r)284 break285 }286 switch req.Key {287 case "sendMail": // 控制是否发送邮件288 var sendOrNot bool289 sendOrNot, err = strconv.ParseBool(req.Value)290 if err == nil {291 logs.Info("Email config change: sendCallDriverEmail=%v", sendOrNot)292 sendCallDriverEmail = sendOrNot293 }294 default:295 err = fmt.Errorf("unexpect key: %s", req.Key)296 }297 }298 logs.Info("contral result: req=%v err=%v", req, err)299 if err != nil {300 resp.Status = -1301 resp.Msg = fmt.Sprint(err)302 } else {303 resp.Status = 0304 }305 bytes, _ := json.Marshal(resp)306 fmt.Fprintf(w, "%s", bytes)307}...

Full Screen

Full Screen

navigator.go

Source:navigator.go Github

copy

Full Screen

...16 //var retsult map[string]interface{} 只有定義 type 還沒 new variable17 retsult := map[string]interface{}{}18 retsult["prev"] = map[string]interface{}{}19 retsult["next"] = map[string]interface{}{}20 //retsult["naviLoop"] = []interface{}{}21 naviLoop := []interface{}{}22 link := uri + "/"23 strget := ""24 if len(argc) > 0 {25 getParam := argc[0]26 if len(getParam) > 0 {27 strget = "?"28 for key, value := range getParam {29 strget = strget + fmt.Sprintf("%s=%s&", key, value)30 }31 }32 }33 options := map[string]interface{}{}34 if len(argc) > 1 {35 options = argc[1]36 }37 //fmt.Println(options)38 prevText, _ := options["prevText"]39 if prevText == nil {40 prevText = "Prev"41 }42 //fmt.Println("prevText:" + prevText)43 nextText, _ := options["nextText"]44 if nextText == nil {45 nextText = "Next"46 }47 //fmt.Println("nextText:" + nextText)48 //options49 if prevnext, _ := options["prevnext"]; prevnext != "disabled" {50 if page == 1 {51 if prevText == nil {52 retsult["prev"] = map[string]interface{}{"link": "#", "disabled": true}53 } else {54 retsult["prev"] = map[string]interface{}{"link": "#", "disabled": true, "text": prevText}55 }56 }57 if page > 1 {58 link = uri + "/"59 link = link + fmt.Sprintf("%d", page-1) + "/" + strget60 if prevText == nil {61 retsult["prev"] = map[string]interface{}{"link": link, "disabled": false}62 } else {63 retsult["prev"] = map[string]interface{}{"link": link, "disabled": false, "text": prevText}64 }65 }66 if page == totalpage {67 if nextText == nil {68 retsult["next"] = map[string]interface{}{"link": "#", "disabled": true}69 } else {70 retsult["next"] = map[string]interface{}{"link": "#", "disabled": true, "text": nextText}71 }72 }73 if page < totalpage && page >= 1 {74 link = uri + "/"75 link = link + fmt.Sprintf("%d", page+1) + "/" + strget76 if nextText == nil {77 retsult["next"] = map[string]interface{}{"link": link, "disabled": false}78 } else {79 retsult["next"] = map[string]interface{}{"link": link, "disabled": false, "text": nextText}80 }81 }82 }83 if justify, _ := options["justify"]; justify != nil {84 retsult["justify"] = justify85 }86 // target := ""87 // target, _ = options["target"]88 // if target != "" {89 // retsult["target"] = target90 // }91 // fmt.Println("target:" + target)92 if size, _ := options["size"]; size != nil {93 if size == "lg" {94 retsult["sizeClass"] = "pagination-lg"95 }96 if size == "sm" {97 retsult["sizeClass"] = "pagination-sm"98 }99 }100 for i := 1; i <= totalpage; i++ {101 navi := map[string]interface{}{}102 if totalpage < 10 {103 if i == page {104 navi = map[string]interface{}{"link": "#", "disabled": false, "active": true, "num": i}105 } else {106 link = uri + "/"107 link = link + fmt.Sprintf("%d", i) + "/" + strget108 navi = map[string]interface{}{"link": link, "disabled": false, "num": i}109 }110 naviLoop = append(naviLoop, navi)111 } else {112 if i < 3 {113 if i == page {114 navi = map[string]interface{}{"link": "#", "disabled": false, "active": true, "num": i}115 } else {116 link = uri + "/"117 link = link + fmt.Sprintf("%d", i) + "/" + strget118 navi = map[string]interface{}{"link": link, "disabled": false, "num": i}119 }120 if page == 1 && i == 2 {121 navi["dotNext"] = true122 }123 naviLoop = append(naviLoop, navi)124 } else if i > (totalpage - 2) {125 if i == page {126 navi = map[string]interface{}{"link": "#", "disabled": false, "active": true, "num": i}127 } else {128 link = uri + "/"129 link = link + fmt.Sprintf("%d", i) + "/" + strget130 navi = map[string]interface{}{"link": link, "disabled": false, "num": i}131 }132 if page == totalpage && i == (totalpage-1) {133 navi["dotPrev"] = true134 }135 naviLoop = append(naviLoop, navi)136 } else if i >= (page-1) && i <= (page+1) {137 if i == page {138 navi = map[string]interface{}{"link": "#", "disabled": false, "active": true, "num": i}139 } else {140 link = uri + "/"141 link = link + fmt.Sprintf("%d", i) + "/" + strget142 navi = map[string]interface{}{"link": link, "disabled": false, "num": i}143 }144 if i == (page - 1) {145 navi["dotPrev"] = true146 }147 if i == (page + 1) {148 navi["dotNext"] = true149 }150 naviLoop = append(naviLoop, navi)151 }152 }153 //fmt.Println(navi)154 }155 //fmt.Println(naviLoop)156 retsult["naviLoop"] = naviLoop157 return retsult158}159/*ExecHTML return HTML160* @m map data for template parse data161* @name element template name162 */163func ExecHTML(m map[string]interface{}, name string) (string, error) {164 var err error165 path, err := os.Getwd()166 if err != nil {167 log.Println(err)168 }169 html := ""170 //t := template.New("") single template execution no need this line...

Full Screen

Full Screen

Loop

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 if err != nil {4 fmt.Println("Error loading HTTP response: ", err)5 }6 defer res.Body.Close()7 if res.StatusCode != 200 {8 fmt.Println("Error status code: ", res.StatusCode)9 }10 doc, err := goquery.NewDocumentFromReader(res.Body)11 if err != nil {12 fmt.Println("Error loading HTTP response body: ", err)13 }14 doc.Find(".review").Each(func(i int, s *goquery.Selection) {15 band := s.Find("a").Text()16 title := s.Find("i").Text()17 fmt.Printf("Review %d: %s - %s18 })19}20import (21func main() {22 if err != nil {23 fmt.Println("Error loading HTTP response: ", err)24 }25 defer res.Body.Close()26 if res.StatusCode != 200 {27 fmt.Println("Error status code: ", res.StatusCode)28 }29 doc, err := goquery.NewDocumentFromReader(res.Body)30 if err != nil {31 fmt.Println("Error loading HTTP response body: ", err)32 }33 reviewItems := doc.Find(".review")34 reviewItems.Each(func(i int, s *goquery.Selection) {35 band := s.Find("a").Text()36 title := s.Find("i").Text()37 results = append(results, fmt.Sprintf("Review %d: %s - %s", i, band, title

Full Screen

Full Screen

Loop

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 f, err := os.Open("1.html")4 if err != nil {5 fmt.Println(err)6 }7 defer f.Close()8 doc, err := html.Parse(f)9 if err != nil {10 fmt.Println(err)11 }12 visit(nil, doc)13}14func visit(stack []string, n *html.Node) {15 if n.Type == html.ElementNode {16 stack = append(stack, n.Data)17 }18 if n.Type == html.TextNode {19 fmt.Println(stack, n.Data)20 }21 for c := n.FirstChild; c != nil; c = c.NextSibling {22 visit(stack, c)23 }24}

Full Screen

Full Screen

Loop

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 if err != nil {4 fmt.Println("Error : ", err)5 }6 defer resp.Body.Close()7 doc, err := html.Parse(resp.Body)8 if err != nil {9 fmt.Println("Error : ", err)10 }11 var f func(*html.Node)12 f = func(n *html.Node) {13 if n.Type == html.ElementNode && n.Data == "a" {14 for _, a := range n.Attr {15 if a.Key == "href" {16 fmt.Println(a.Val)17 }18 }19 }20 for c := n.FirstChild; c != nil; c = c.NextSibling {21 f(c)22 }23 }24 f(doc)25}

Full Screen

Full Screen

Loop

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 if err != nil {4 panic(err.Error())5 }6 defer res.Body.Close()7 doc, err := goquery.NewDocumentFromReader(res.Body)8 if err != nil {9 panic(err.Error())10 }11 doc.Find(".r").Each(func(i int, s *goquery.Selection) {12 band := s.Find("a").Text()13 title := s.Find("i").Text()14 fmt.Printf("Review %d: %s - %s15 })16}

Full Screen

Full Screen

Loop

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 response, err := http.Get(url)4 if err != nil {5 log.Fatal(err)6 }7 defer response.Body.Close()8 document, err := goquery.NewDocumentFromReader(response.Body)9 if err != nil {10 log.Fatal(err)11 }12 document.Find("a").Each(func(index int, element *goquery.Selection) {13 link, _ := element.Attr("href")14 fmt.Println(link)15 })16}17import (18func main() {19 response, err := http.Get(url)20 if err != nil {21 log.Fatal(err)22 }23 defer response.Body.Close()24 document, err := goquery.NewDocumentFromReader(response.Body)25 if err != nil {26 log.Fatal(err)27 }28 document.Find("a").Each(func(index int, element *goquery.Selection) {29 link, _ := element.Attr("href")30 fmt.Println(link)31 })32}33import (34func main() {35 response, err := http.Get(url)36 if err != nil {37 log.Fatal(err)38 }39 defer response.Body.Close()40 document, err := goquery.NewDocumentFromReader(response.Body)41 if err != nil {42 log.Fatal(err)43 }44 document.Find("a").Each(func(index int, element *goquery.Selection) {45 link, _ := element.Attr("href")46 fmt.Println(link)47 })48}49import (50func main() {51 response, err := http.Get(url)52 if err != nil {53 log.Fatal(err)54 }55 defer response.Body.Close()

Full Screen

Full Screen

Loop

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 r, _ := os.Open("index.html")4 io.Copy(os.Stdout, r)5}6import (7func main() {8 r, _ := os.Open("index.html")9 io.Copy(os.Stdout, r)10}11import (12func main() {13 r, _ := os.Open("index.html")14 io.Copy(os.Stdout, r)15}16import (17func main() {18 r, _ := os.Open("index.html")19 io.Copy(os.Stdout, r)20}21import (22func main() {23 r, _ := os.Open("index.html")24 io.Copy(os.Stdout, r)25}26import (27func main() {28 r, _ := os.Open("index.html")29 io.Copy(os.Stdout, r)30}31import (32func main() {33 r, _ := os.Open("index.html")34 io.Copy(os.Stdout, r)35}36import (37func main() {38 r, _ := os.Open("index.html")39 io.Copy(os.Stdout, r)40}41import (42func main() {43 r, _ := os.Open("index.html")44 io.Copy(os.Stdout, r)45}46import (

Full Screen

Full Screen

Loop

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 for i:=0; i<5; i++ {4 fmt.Println("Hello, World!")5 }6}7import "fmt"8func main() {9 for i:=0; i<5; i++ {10 fmt.Println("Hello, World!")11 }12}13import "fmt"14func main() {15 for i:=0; i<5; i++ {16 fmt.Println("Hello, World!")17 }18}19import "fmt"20func main() {21 for i:=0; i<5; i++ {22 fmt.Println("Hello, World!")23 }24}25import "fmt"26func main() {27 for i:=0; i<5; i++ {28 fmt.Println("Hello, World!")29 }30}31import "fmt"32func main() {33 for i:=0; i<5; i++ {34 fmt.Println("Hello, World!")35 }36}37import "fmt"38func main() {39 for i:=0; i<5; i++ {40 fmt.Println("Hello, World!")41 }42}43import "fmt"44func main() {45 for i:=0; i<5; i++ {46 fmt.Println("Hello, World!")47 }48}

Full Screen

Full Screen

Loop

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Enter the url")4 fmt.Scan(&url)5 resp, err := http.Get(url)6 if err != nil {7 log.Fatal(err)8 }9 body, err := ioutil.ReadAll(resp.Body)10 if err != nil {11 log.Fatal(err)12 }13 node, err := html.Parse(string(body))14 if err != nil {15 log.Fatal(err)16 }17 html.Loop(node, func(node *html.Node) bool {18 fmt.Printf("%T19 })20}

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 K6 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