Created
April 24, 2021 21:13
-
-
Save buroz/7fb467212994e70d7660f061d83cb483 to your computer and use it in GitHub Desktop.
Trendyol Ürün Detay & Rekabet Listesi
This file contains hidden or 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 ( | |
"encoding/json" | |
"fmt" | |
"io/ioutil" | |
"net/http" | |
"regexp" | |
"strings" | |
) | |
type InitialState struct { | |
Product struct { | |
Attributes []interface{} `json:"attributes"` | |
AlternativeVariants []interface{} `json:"alternativeVariants"` | |
Variants []struct { | |
AttributeID int `json:"attributeId"` | |
AttributeName string `json:"attributeName"` | |
AttributeType string `json:"attributeType"` | |
AttributeValue string `json:"attributeValue"` | |
Stamps []struct { | |
Type int `json:"type"` | |
Text string `json:"text"` | |
} `json:"stamps"` | |
Price struct { | |
ProfitMargin int `json:"profitMargin"` | |
DiscountedPrice struct { | |
Text string `json:"text"` | |
Value float64 `json:"value"` | |
} `json:"discountedPrice"` | |
SellingPrice struct { | |
Text string `json:"text"` | |
Value float64 `json:"value"` | |
} `json:"sellingPrice"` | |
OriginalPrice struct { | |
Text string `json:"text"` | |
Value float64 `json:"value"` | |
} `json:"originalPrice"` | |
Currency string `json:"currency"` | |
} `json:"price"` | |
AttributeBeautifiedValue string `json:"attributeBeautifiedValue"` | |
IsWinner bool `json:"isWinner"` | |
ListingID string `json:"listingId"` | |
Stock interface{} `json:"stock"` | |
Sellable bool `json:"sellable"` | |
AvailableForClaim bool `json:"availableForClaim"` | |
Barcode string `json:"barcode"` | |
ItemNumber int `json:"itemNumber"` | |
DiscountedPriceInfo string `json:"discountedPriceInfo"` | |
UnitInfo struct { | |
UnitPrice bool `json:"unitPrice"` | |
UnitPriceText bool `json:"unitPriceText"` | |
} `json:"unitInfo"` | |
} `json:"variants"` | |
OtherMerchants []struct { | |
URL string `json:"url"` | |
ReviewsURL string `json:"reviewsUrl"` | |
QuestionsURL string `json:"questionsUrl"` | |
Promotions []interface{} `json:"promotions"` | |
DiscountedPriceInfo string `json:"discountedPriceInfo"` | |
IsSellable bool `json:"isSellable"` | |
IsBasketDiscount bool `json:"isBasketDiscount"` | |
HasStock bool `json:"hasStock"` | |
Price struct { | |
ProfitMargin int `json:"profitMargin"` | |
DiscountedPrice struct { | |
Text string `json:"text"` | |
Value float64 `json:"value"` | |
} `json:"discountedPrice"` | |
SellingPrice struct { | |
Text string `json:"text"` | |
Value float64 `json:"value"` | |
} `json:"sellingPrice"` | |
OriginalPrice struct { | |
Text string `json:"text"` | |
Value float64 `json:"value"` | |
} `json:"originalPrice"` | |
Currency string `json:"currency"` | |
} `json:"price"` | |
IsFreeCargo bool `json:"isFreeCargo"` | |
Merchant struct { | |
IsSearchableMerchant bool `json:"isSearchableMerchant"` | |
ID int `json:"id"` | |
Name string `json:"name"` | |
OfficialName string `json:"officialName"` | |
CityName string `json:"cityName"` | |
TaxNumber string `json:"taxNumber"` | |
SellerScore float64 `json:"sellerScore"` | |
SellerScoreColor string `json:"sellerScoreColor"` | |
} `json:"merchant,omitempty"` | |
DeliveryInformation struct { | |
IsRushDelivery bool `json:"isRushDelivery"` | |
DeliveryDate string `json:"deliveryDate"` | |
} `json:"deliveryInformation"` | |
} `json:"otherMerchants"` | |
Campaign struct { | |
ID int `json:"id"` | |
Name string `json:"name"` | |
StartDate string `json:"startDate"` | |
EndDate string `json:"endDate"` | |
IsMultipleSupplied bool `json:"isMultipleSupplied"` | |
StockTypeID int `json:"stockTypeId"` | |
URL string `json:"url"` | |
ShowTimer bool `json:"showTimer"` | |
} `json:"campaign"` | |
Category struct { | |
ID int `json:"id"` | |
Name string `json:"name"` | |
Hierarchy string `json:"hierarchy"` | |
Refundable bool `json:"refundable"` | |
BeautifiedName string `json:"beautifiedName"` | |
} `json:"category"` | |
Brand struct { | |
IsVirtual bool `json:"isVirtual"` | |
BeautifiedName string `json:"beautifiedName"` | |
ID int `json:"id"` | |
Name string `json:"name"` | |
Path string `json:"path"` | |
} `json:"brand"` | |
Color string `json:"color"` | |
ShowVariants bool `json:"showVariants"` | |
ShowSexualContent bool `json:"showSexualContent"` | |
MetaBrand struct { | |
ID int `json:"id"` | |
Name string `json:"name"` | |
BeautifiedName string `json:"beautifiedName"` | |
IsVirtual bool `json:"isVirtual"` | |
Path string `json:"path"` | |
} `json:"metaBrand"` | |
Landings []interface{} `json:"landings"` | |
ID int `json:"id"` | |
ProductCode string `json:"productCode"` | |
Name string `json:"name"` | |
NameWithProductCode string `json:"nameWithProductCode"` | |
Description string `json:"description"` | |
ContentDescriptions []struct { | |
Description string `json:"description"` | |
Bold bool `json:"bold"` | |
} `json:"contentDescriptions"` | |
ProductGroupID int `json:"productGroupId"` | |
Tax int `json:"tax"` | |
BusinessUnit string `json:"businessUnit"` | |
MaxInstallment int `json:"maxInstallment"` | |
Gender struct { | |
} `json:"gender"` | |
URL string `json:"url"` | |
Images []string `json:"images"` | |
IsSellable bool `json:"isSellable"` | |
IsBasketDiscount bool `json:"isBasketDiscount"` | |
HasStock bool `json:"hasStock"` | |
Price struct { | |
ProfitMargin int `json:"profitMargin"` | |
DiscountedPrice struct { | |
Text string `json:"text"` | |
Value float64 `json:"value"` | |
} `json:"discountedPrice"` | |
SellingPrice struct { | |
Text string `json:"text"` | |
Value float64 `json:"value"` | |
} `json:"sellingPrice"` | |
OriginalPrice struct { | |
Text string `json:"text"` | |
Value float64 `json:"value"` | |
} `json:"originalPrice"` | |
Currency string `json:"currency"` | |
} `json:"price"` | |
IsFreeCargo bool `json:"isFreeCargo"` | |
Promotions []interface{} `json:"promotions"` | |
Merchant struct { | |
IsSearchableMerchant bool `json:"isSearchableMerchant"` | |
ID int `json:"id"` | |
Name string `json:"name"` | |
OfficialName string `json:"officialName"` | |
CityName string `json:"cityName"` | |
TaxNumber string `json:"taxNumber"` | |
SellerScore float64 `json:"sellerScore"` | |
SellerScoreColor string `json:"sellerScoreColor"` | |
SellerLink string `json:"sellerLink"` | |
} `json:"merchant"` | |
DeliveryInformation struct { | |
IsRushDelivery bool `json:"isRushDelivery"` | |
DeliveryDate string `json:"deliveryDate"` | |
} `json:"deliveryInformation"` | |
IsMarketplace bool `json:"isMarketplace"` | |
ProductStamps []interface{} `json:"productStamps"` | |
HasHTMLContent bool `json:"hasHtmlContent"` | |
FavoriteCount int `json:"favoriteCount"` | |
UxLayout string `json:"uxLayout"` | |
IsDigitalGood bool `json:"isDigitalGood"` | |
IsRunningOut bool `json:"isRunningOut"` | |
ScheduledDelivery bool `json:"scheduledDelivery"` | |
RatingScore struct { | |
AverageRating float64 `json:"averageRating"` | |
TotalRatingCount int `json:"totalRatingCount"` | |
TotalCommentCount int `json:"totalCommentCount"` | |
} `json:"ratingScore"` | |
ShowStarredAttributes bool `json:"showStarredAttributes"` | |
ReviewsURL string `json:"reviewsUrl"` | |
QuestionsURL string `json:"questionsUrl"` | |
SellerQuestionEnabled bool `json:"sellerQuestionEnabled"` | |
Breadcrumb struct { | |
Items []struct { | |
Path string `json:"path"` | |
Name string `json:"name"` | |
} `json:"items"` | |
} `json:"breadcrumb"` | |
} `json:"product"` | |
HTMLContent interface{} `json:"htmlContent"` | |
User struct { | |
LoggedIn bool `json:"loggedIn"` | |
ID int `json:"id"` | |
IsBuyer bool `json:"isBuyer"` | |
} `json:"user"` | |
Configuration struct { | |
HTMLContentCSSURL string `json:"htmlContentCssUrl"` | |
HTMLContentJsURL string `json:"htmlContentJsUrl"` | |
StorefrontID int `json:"storefrontId"` | |
ShowPaymentMethodsAndShippings bool `json:"showPaymentMethodsAndShippings"` | |
ShowDiscountInformation bool `json:"showDiscountInformation"` | |
IsDynamicRender bool `json:"isDynamicRender"` | |
IsInternational bool `json:"isInternational"` | |
Culture string `json:"culture"` | |
CdnURL string `json:"cdnUrl"` | |
ClaimInfoText string `json:"claimInfoText"` | |
QuestionsAndAnswersEnabled bool `json:"questionsAndAnswersEnabled"` | |
RatingReviewEnabled bool `json:"ratingReviewEnabled"` | |
RatingReviewLikesEnabled bool `json:"ratingReviewLikesEnabled"` | |
NewRatingSummaryEnabled bool `json:"newRatingSummaryEnabled"` | |
RedirectReviewsPageEnabled bool `json:"redirectReviewsPageEnabled"` | |
LanguageCode string `json:"languageCode"` | |
SizeCharts [][]string `json:"sizeCharts"` | |
EnhancedEcommerceEnabled bool `json:"enhancedEcommerceEnabled"` | |
AddReviewEnabled bool `json:"addReviewEnabled"` | |
ReviewReportAbuseEnabled bool `json:"reviewReportAbuseEnabled"` | |
ShowImageOnProductCommentsEnabled bool `json:"showImageOnProductCommentsEnabled"` | |
CrossProductsTitle string `json:"crossProductsTitle"` | |
CrossProductsEnabled bool `json:"crossProductsEnabled"` | |
RecommendationEnabled bool `json:"recommendationEnabled"` | |
ProductGroupEnabled bool `json:"productGroupEnabled"` | |
HTMLContentEnabled bool `json:"htmlContentEnabled"` | |
ProductAttributesEnabled bool `json:"productAttributesEnabled"` | |
PublishCriteriaEnabled bool `json:"publishCriteriaEnabled"` | |
SellerAreaEnabled bool `json:"sellerAreaEnabled"` | |
SellerPointLowLimit int `json:"sellerPointLowLimit"` | |
SizeChartURL string `json:"sizeChartUrl"` | |
ProductDetailMetaDescription string `json:"productDetailMetaDescription"` | |
SchemaJSONEnabled bool `json:"schemaJsonEnabled"` | |
SiteAddress string `json:"siteAddress"` | |
NotifyMeEnabled bool `json:"notifyMeEnabled"` | |
NotifyMeCount int `json:"notifyMeCount"` | |
AccountGwFavoritesEnabled bool `json:"accountGwFavoritesEnabled"` | |
RecommendationAbTestValue string `json:"recommendationAbTestValue"` | |
LastProductCountAbTestValue string `json:"lastProductCountAbTestValue"` | |
RecoCardAbTestValue string `json:"recoCardAbTestValue"` | |
AbTestingCookieName string `json:"abTestingCookieName"` | |
ClientSideReviewsEnabled bool `json:"clientSideReviewsEnabled"` | |
ClientSideHTMLContentEnabled bool `json:"clientSideHtmlContentEnabled"` | |
AlternativeVariantsEnabled bool `json:"alternativeVariantsEnabled"` | |
RelatedCategoryEnabled bool `json:"relatedCategoryEnabled"` | |
RelatedCategoryAbTestVariant string `json:"relatedCategoryAbTestVariant"` | |
RelatedCategoryAbTestValue string `json:"relatedCategoryAbTestValue"` | |
RelatedCategoryTitleTooltipThreshold int `json:"relatedCategoryTitleTooltipThreshold"` | |
RelatedCategoryCountLimit int `json:"relatedCategoryCountLimit"` | |
RelatedCategoryImageVirtualBrandIds []int `json:"relatedCategoryImageVirtualBrandIds"` | |
RelatedCategoryVirtualBrandImagePath string `json:"relatedCategoryVirtualBrandImagePath"` | |
DefaultBrandCategoryCombinationImageURL string `json:"defaultBrandCategoryCombinationImageUrl"` | |
LegalRequirementCacheDuration int `json:"legalRequirementCacheDuration"` | |
DigitalGoodsDeliveryText string `json:"digitalGoodsDeliveryText"` | |
RecoCrossCustomStampsEnabled bool `json:"recoCrossCustomStampsEnabled"` | |
CanShowSizeChartButton bool `json:"canShowSizeChartButton"` | |
ProductDetailImprovedBreadcrumbEnabled bool `json:"productDetailImprovedBreadcrumbEnabled"` | |
SellerShippingEnabled bool `json:"sellerShippingEnabled"` | |
ProductDetailReportAbuseEnabled bool `json:"productDetailReportAbuseEnabled"` | |
ProductDetailReportAbuseItems string `json:"productDetailReportAbuseItems"` | |
ScheduledDeliveryWarningMessage string `json:"scheduledDeliveryWarningMessage"` | |
InstallmentStampAmountText string `json:"installmentStampAmountText"` | |
StarredAttributesLimit int `json:"starredAttributesLimit"` | |
SellerStoreLinkEnabled bool `json:"sellerStoreLinkEnabled"` | |
FeaturedCardFavButtonEnabled bool `json:"featuredCardFavButtonEnabled"` | |
OpenReviewModalEnabled bool `json:"openReviewModalEnabled"` | |
InstallmentCountToDisplay int `json:"installmentCountToDisplay"` | |
CurrencySymbol string `json:"currencySymbol"` | |
NewSearchEnabled bool `json:"newSearchEnabled"` | |
StampType string `json:"stampType"` | |
MemberGwURL string `json:"memberGwUrl"` | |
GetNotifyMePreferencesFromMemberGw bool `json:"getNotifyMePreferencesFromMemberGw"` | |
PublicProductGwURL string `json:"publicProductGwUrl"` | |
PublicSdcProductGwURL string `json:"publicSdcProductGwUrl"` | |
PublicMdcProductGwURL string `json:"publicMdcProductGwUrl"` | |
} `json:"configuration"` | |
} | |
func (s *InitialState) Parse(str string) error { | |
return json.Unmarshal([]byte(str), &s) | |
} | |
func call(url string) (string, error) { | |
client := &http.Client{} | |
req, _ := http.NewRequest("GET", url, nil) | |
req.Header.Set("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:88.0) Gecko/20100101 Firefox/88.0") | |
req.Header.Set("Accept-Language", "en-US,en;q=0.5") | |
req.Header.Set("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8") | |
res, _ := client.Do(req) | |
body, err := ioutil.ReadAll(res.Body) | |
if err != nil { | |
return "", err | |
} | |
return string(body), nil | |
} | |
func trimJson(str string) string { | |
re := regexp.MustCompile(`(?s)window.__PRODUCT_DETAIL_APP_INITIAL_STATE__=(.*);window.TYPageName`) | |
if len(re.FindStringIndex(str)) > 0 { | |
str = strings.Replace(re.FindString(str), "window.__PRODUCT_DETAIL_APP_INITIAL_STATE__=", "", 1) | |
str = strings.Replace(str, ";window.TYPageName", "", 1) | |
return str | |
} | |
return "" | |
} | |
func main() { | |
url := "https://www.trendyol.com/apple/iphone-orjinal-sarj-aleti-kablosu-1m-lightning-usb-kablosu-p-57687100" | |
str, _ := call(url) | |
str = trimJson(str) | |
var state = InitialState{} | |
_ = state.Parse(str) | |
for _, merchant := range state.Product.OtherMerchants { | |
// Diğer fiyatlar | |
fmt.Println(merchant.Price.DiscountedPrice.Value) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment