Example #1
0
        public async Task <TwitterTweetPageModel> GetUserTweetsAsync(TwitterOption option, Dictionary <string, string> paramDict)
        {
            var url = $"{AddressLocator.Web}/search/timeline";

            url = AddressLocator.SanitizeQuery(url, paramDict);
            var htmlSource = await HtmlLoader.TryLoadPageAsync(url, GetRandomProxy(), true, false);

            if (!string.IsNullOrEmpty(htmlSource))
            {
                if (RawTweetPage.TryParse(htmlSource, out var rawPage))
                {
                    var           parser  = new HtmlParser();
                    IHtmlDocument htmlDoc = null;
                    try
                    {
                        htmlDoc = await parser.ParseDocumentAsync(rawPage.ItemsHtml);
                    }
                    catch (Exception)
                    {
                    }

                    if (htmlDoc != null)
                    {
                        if (HtmlExtracter.TryParseTweet(option, htmlDoc, out var pageModel))
                        {
                            pageModel.NextPageParams = new Dictionary <string, string>(paramDict);
                            pageModel.HasNext        = rawPage.HasMoreItems;
                            pageModel.SetMaxPosition(rawPage.MinPosition);
                            pageModel.Options = option;
                            return(pageModel);
                        }
                    }
                }
            }


            return(null);
        }