Exemplo n.º 1
0
        public static AllDataSheetSearchResult Search(string value)
        {
            string         url     = $"{SiteAddress}?Searchword={value}&sPage=1&sField=4";
            HttpWebRequest request = Requests.CreateDefaultRequest(url);
            string         result  = Requests.ReadResponseString(request);

            HtmlDocument document = new HtmlDocument();

            document.LoadHtml(result);

            int totalPages;

            AllDataSheetSearchContext.SearchOption option;
            FilterSearchMode(document, out totalPages, out option);

            AllDataSheetSearchContext searchContext = new AllDataSheetSearchContext(value);

            searchContext.NextPage   = 1;
            searchContext.TotalPages = totalPages;
            if (option != AllDataSheetSearchContext.SearchOption.Match)
            {
                searchContext.UsedOptions.Add(AllDataSheetSearchContext.SearchOption.Match);
                searchContext.Option = option;
            }
            searchContext.Next(url);

            AllDataSheetSearchResult ret = new AllDataSheetSearchResult();

            ret.Parts         = FilterResults(document);
            ret.SearchContext = searchContext;

            return(ret);
        }
Exemplo n.º 2
0
        public static AllDataSheetSearchResult Search(AllDataSheetSearchContext searchContext)
        {
            if (!searchContext.CanLoadMore)
            {
                AllDataSheetSearchResult ret = new AllDataSheetSearchResult();
                ret.Parts         = null;
                ret.SearchContext = searchContext;
                return(ret);
            }

            while (true)
            {
                string         url     = $"{SiteAddress}?Searchword={searchContext.SearchValue}&sPage={searchContext.NextPage}&sField={(int)searchContext.Option}";
                HttpWebRequest request = Requests.CreateDefaultRequest(url);
                request.Referer = searchContext.Referer;
                string result = Requests.ReadResponseString(request);

                HtmlDocument document = new HtmlDocument();
                document.LoadHtml(result);

                if (searchContext.NextPage == 1)
                {
                    int totalPages;
                    AllDataSheetSearchContext.SearchOption option;
                    FilterSearchMode(document, out totalPages, out option);
                    searchContext.TotalPages = totalPages;
                    if (searchContext.Option != option)
                    {
                        if (!searchContext.UsedOptions.Contains(searchContext.Option))
                        {
                            searchContext.UsedOptions.Add(searchContext.Option);
                        }
                        searchContext.Option = option;
                    }
                }

                AllDataSheetSearchResult sret = new AllDataSheetSearchResult();
                if (searchContext.UsedOptions.Contains(searchContext.Option))
                {
                    sret.Parts = new List <AllDataSheetPart>();
                    if (searchContext.CanLoadMore)
                    {
                        searchContext.Next(url);
                        continue;
                    }
                }
                else
                {
                    sret.Parts = FilterResults(document);
                }

                sret.SearchContext = searchContext;
                searchContext.Next(url);

                return(sret);
            }
        }
Exemplo n.º 3
0
        public MoreInfo RequestMoreInfo()
        {
            HttpWebRequest request = Requests.CreateDefaultRequest(m_datasheetSiteLink);
            string         result  = Requests.ReadResponseString(request);

            HtmlDocument document = new HtmlDocument();

            document.LoadHtml(result);

            HtmlNode rootElement = document.DocumentNode;

            IEnumerable <HtmlNode> matchingNodes = from node in rootElement.Descendants("td")
                                                   where IsAttributeValueLike(node, "width", "283") && IsAttributeValueLike(node, "height", "367") &&
                                                   IsAttributeValueLike(node, "align", "center") && IsAttributeValueLike(node, "valign", "top")
                                                   select node;

            HtmlNode aNode = matchingNodes.ElementAt(0).Element("a");

            MoreInfo moreInfo = new MoreInfo();

            moreInfo.PdfSite = GetAttributeValueOrEmpty(aNode, "href");

            matchingNodes = from node in rootElement.Descendants("td")
                            where IsAttributeValueLike(node, "height", "40") && IsAttributeValueLike(node, "class", "gray_title") &&
                            IsAttributeValueLike(node, "width", "88")
                            select node;

            HtmlNode sizeNode = matchingNodes.ElementAt(2).ParentNode;

            moreInfo.Size = sizeNode.Elements("td").ElementAt(1).Element("font").InnerText;

            HtmlNode pagesNode = matchingNodes.ElementAt(3).ParentNode;

            moreInfo.Pages = pagesNode.Elements("td").ElementAt(1).Element("font").InnerText;

            HtmlNode manufacturerSiteNode = matchingNodes.ElementAt(5).ParentNode;

            moreInfo.ManufacturerSite = manufacturerSiteNode.Elements("td").ElementAt(1).InnerText;

            return(moreInfo);
        }
Exemplo n.º 4
0
        public Stream GetDatasheetStream(string pdfSite)
        {
            Uri    pdfUri  = new Uri(pdfSite);
            string pdfHost = pdfUri.GetLeftPart(UriPartial.Scheme) + pdfUri.Host;

            CookieContainer cookies = new CookieContainer();

            HttpWebRequest request = Requests.CreateDefaultRequest(pdfSite);

            request.Referer         = m_datasheetSiteLink;
            request.CookieContainer = cookies;
            string result = Requests.ReadResponseString(request);

            HtmlDocument document = new HtmlDocument();

            document.LoadHtml(result);

            HtmlNode rootElement = document.DocumentNode;

            IEnumerable <HtmlNode> matchingNodes = from node in rootElement.Descendants("iframe")
                                                   where IsAttributeValueLike(node, "height", "810") && IsAttributeValueLike(node, "name", "333") && IsAttributeValueLike(node, "width", "100%")
                                                   select node;

            string pdfPath = GetAttributeValueOrEmpty(matchingNodes.ElementAt(0), "src");

            string pdfDirect = pdfHost + pdfPath;

            cookies.Add(new Uri(pdfDirect), cookies.GetCookies(new Uri(pdfSite)));

            request                 = Requests.CreateDefaultRequest(pdfDirect);
            request.Referer         = pdfSite;
            request.CookieContainer = cookies;
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();

            return(response.GetResponseStream());
        }