Browse Source

修复1688爬虫问题

pjzs_starttask_update
shanji 2 years ago
parent
commit
24f6dd6f72
  1. 4
      BBWY.Client/APIServices/PurchaseProductAPIService.cs
  2. 5
      BBWY.Server.API/Startup.cs
  3. 9
      BBWY.Server.Business/PurchaseScheme/PurchaseProductAPIService.cs

4
BBWY.Client/APIServices/PurchaseProductAPIService.cs

@ -189,7 +189,7 @@ namespace BBWY.Client.APIServices
if (_1688pageResult.StatusCode != System.Net.HttpStatusCode.OK)
return null;
var match = Regex.Match(_1688pageResult.Content, @"(window\.__INIT_DATA=)(.*)(\r*\n*\s*</script>)");
var match = Regex.Match(_1688pageResult.Content, @"(window\.__INIT_DATA\s?=)(.*)(\r*\n*\s*</script>)");
if (!match.Success)
return null;
@ -238,7 +238,7 @@ namespace BBWY.Client.APIServices
SkuId = skuId,
PurchaseProductId = purchaseProductId,
Price = skuPrice == 0M ? firstPrice : skuPrice,
Title = name,
Title = matchName,
PurchaseSkuId = value.Value<string>("skuId"),
PurchaseSkuSpecId = value.Value<string>("specId"),
Logo = colorsProperty.FirstOrDefault(c => c.name == matchName)?.imageUrl ?? "pack://application:,,,/Resources/Images/defaultItem.png"

5
BBWY.Server.API/Startup.cs

@ -19,6 +19,7 @@ using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Reflection;
using System.Text;
using Yitter.IdGenerator;
@ -65,6 +66,10 @@ namespace BBWY.Server.API
services.AddControllers();
services.AddHttpContextAccessor();
services.AddHttpClient();
services.AddHttpClient("gzip").ConfigurePrimaryHttpMessageHandler(handler => new HttpClientHandler()
{
AutomaticDecompression = System.Net.DecompressionMethods.GZip
});
services.AddCors(options =>
{
options.AddPolicy("cors", p =>

9
BBWY.Server.Business/PurchaseScheme/PurchaseProductAPIService.cs

@ -40,7 +40,7 @@ namespace BBWY.Server.Business
this.restApiService = restApiService;
_1688ProductDetailRequestHeader = new Dictionary<string, string>()
{
{ "Host","detail.1688.com"},
//{ "Host","detail.1688.com"},
{ "User-Agent","Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.5112.102 Safari/537.36 Edg/104.0.1293.70"},
{ "Accept","text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"},
{ "Accept-Encoding","gzip, deflate, br"},
@ -193,12 +193,13 @@ namespace BBWY.Server.Business
$"clickid={Guid.NewGuid().ToString().Md5Encrypt()}&sessionid={Guid.NewGuid().ToString().Md5Encrypt()}&sk={(request.PriceMode == Enums.PurchaseOrderMode.批发 ? "order" : "consign")}",
_1688ProductDetailRequestHeader,
HttpMethod.Get,
httpClientName: "gzip");
httpClientName: "gzip",
getResponseHeader: true);
if (_1688pageResult.StatusCode != System.Net.HttpStatusCode.OK)
return null;
var match = Regex.Match(_1688pageResult.Content, @"(window\.__INIT_DATA=)(.*)(\r*\n*\s*</script>)");
var match = Regex.Match(_1688pageResult.Content, @"(window\.__INIT_DATA\s?=)(.*)(\r*\n*\s*</script>)");
if (!match.Success)
return null;
@ -246,7 +247,7 @@ namespace BBWY.Server.Business
{
PurchaseProductId = request.PurchaseProductId,
Price = skuPrice == 0M ? firstPrice : skuPrice,
Title = name,
Title = matchName, //name
PurchaseSkuId = value.Value<string>("skuId"),
PurchaseSkuSpecId = value.Value<string>("specId"),
Logo = colorsProperty.FirstOrDefault(c => c.name == matchName)?.imageUrl ?? "pack://application:,,,/Resources/Images/defaultItem.png"

Loading…
Cancel
Save