Add clean request private method

This commit is contained in:
Sergey Chebotar 2021-11-29 17:10:43 +03:00
parent 15995027bf
commit d176a023f0
4 changed files with 10 additions and 3 deletions

View File

@ -3,6 +3,7 @@ using AngleSharp.Dom;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace Rehau.Sku.Assist
@ -11,7 +12,7 @@ namespace Rehau.Sku.Assist
{
public async static Task<string> GetContent(string request, HttpClient httpClient)
{
string uri = "https://shop-rehau.ru/catalogsearch/result/?q=" + request;
string uri = "https://shop-rehau.ru/catalogsearch/result/?q=" + request._CleanRequest();
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
return await httpClient.GetStringAsync(uri);
@ -31,9 +32,13 @@ namespace Rehau.Sku.Assist
.All
.Where(e => e.ClassName == "product-item__desc-top")
.Select(e => new Product(e.Children[0].TextContent, e.Children[1].TextContent.Trim(new[] { '\n', ' ' })))
// .Where(product => !product.Sku.Any(c => char.IsLetter(c)))
.FirstOrDefault();
}
private static string _CleanRequest(this string input)
{
return input.Replace("+", " plus ");
}
}
}

View File

@ -15,7 +15,7 @@ namespace Rehau.Sku.Assist
Task<string> contentTask = Task.Run(() => SkuAssist.GetContent(request, httpClient));
Task<IDocument> documentTask = await contentTask.ContinueWith(content => SkuAssist.GetDocument(content));
IProduct product = await documentTask.ContinueWith(doc => SkuAssist.GetProductFromDocument(doc.Result));
return product.ToString();
return product == null ? ExcelError.ExcelErrorNull.ToString() : product.ToString();
}
}
}

Binary file not shown.

View File

@ -36,6 +36,7 @@
<ItemGroup>
<Reference Include="AngleSharp, Version=0.16.1.0, Culture=neutral, PublicKeyToken=e83494dcdc6d31ea, processorArchitecture=MSIL">
<HintPath>packages\AngleSharp.0.16.1\lib\net472\AngleSharp.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="ExcelDna.Integration, Version=1.1.0.0, Culture=neutral, PublicKeyToken=f225e9659857edbe, processorArchitecture=MSIL">
<HintPath>packages\ExcelDna.Integration.1.5.0\lib\net452\ExcelDna.Integration.dll</HintPath>
@ -43,6 +44,7 @@
</Reference>
<Reference Include="ExcelDna.Registration, Version=1.1.0.0, Culture=neutral, PublicKeyToken=f225e9659857edbe, processorArchitecture=MSIL">
<HintPath>packages\ExcelDna.Registration.1.5.0\lib\net452\ExcelDna.Registration.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Buffers, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">