Add clean request private method
This commit is contained in:
parent
15995027bf
commit
d176a023f0
@ -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 ");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
BIN
Rehau.Sku.Assist-AddIn-packed.xll
Normal file
BIN
Rehau.Sku.Assist-AddIn-packed.xll
Normal file
Binary file not shown.
@ -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">
|
||||
|
Loading…
Reference in New Issue
Block a user