v1.0
This commit is contained in:
parent
1015b1a03c
commit
1f8ec73b0a
25
淘宝网址解析.sln
Normal file
25
淘宝网址解析.sln
Normal file
|
@ -0,0 +1,25 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.5.33424.131
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "淘宝网址解析", "淘宝网址解析\淘宝网址解析.csproj", "{D5486880-F468-4149-86BF-AD79659BC9A0}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{D5486880-F468-4149-86BF-AD79659BC9A0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{D5486880-F468-4149-86BF-AD79659BC9A0}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{D5486880-F468-4149-86BF-AD79659BC9A0}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{D5486880-F468-4149-86BF-AD79659BC9A0}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {7B2779C1-6668-48BC-86EE-635258772CB4}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
203
淘宝网址解析/Form1.Designer.cs
generated
Normal file
203
淘宝网址解析/Form1.Designer.cs
generated
Normal file
|
@ -0,0 +1,203 @@
|
|||
namespace 淘宝网址解析
|
||||
{
|
||||
partial class Form1
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
button1 = new Button();
|
||||
textBox1 = new TextBox();
|
||||
textBox2 = new TextBox();
|
||||
splitContainer1 = new SplitContainer();
|
||||
tableLayoutPanel1 = new TableLayoutPanel();
|
||||
flowLayoutPanel1 = new FlowLayoutPanel();
|
||||
checkBox1 = new CheckBox();
|
||||
checkBox2 = new CheckBox();
|
||||
dataGridView1 = new DataGridView();
|
||||
((System.ComponentModel.ISupportInitialize)splitContainer1).BeginInit();
|
||||
splitContainer1.Panel1.SuspendLayout();
|
||||
splitContainer1.Panel2.SuspendLayout();
|
||||
splitContainer1.SuspendLayout();
|
||||
tableLayoutPanel1.SuspendLayout();
|
||||
flowLayoutPanel1.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)dataGridView1).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// button1
|
||||
//
|
||||
button1.Dock = DockStyle.Fill;
|
||||
button1.Location = new Point(2, 289);
|
||||
button1.Margin = new Padding(2, 3, 2, 3);
|
||||
button1.Name = "button1";
|
||||
button1.Size = new Size(453, 43);
|
||||
button1.TabIndex = 0;
|
||||
button1.Text = "解析";
|
||||
button1.UseVisualStyleBackColor = true;
|
||||
button1.Click += button1_ClickAsync;
|
||||
//
|
||||
// textBox1
|
||||
//
|
||||
textBox1.Dock = DockStyle.Fill;
|
||||
textBox1.Location = new Point(2, 3);
|
||||
textBox1.Margin = new Padding(2, 3, 2, 3);
|
||||
textBox1.Multiline = true;
|
||||
textBox1.Name = "textBox1";
|
||||
textBox1.Size = new Size(453, 233);
|
||||
textBox1.TabIndex = 1;
|
||||
textBox1.Text = "在这里输入需要缩短的淘宝宝贝链接";
|
||||
//
|
||||
// textBox2
|
||||
//
|
||||
textBox2.Dock = DockStyle.Fill;
|
||||
textBox2.Location = new Point(2, 242);
|
||||
textBox2.Margin = new Padding(2, 3, 2, 3);
|
||||
textBox2.Multiline = true;
|
||||
textBox2.Name = "textBox2";
|
||||
textBox2.Size = new Size(453, 41);
|
||||
textBox2.TabIndex = 3;
|
||||
textBox2.Text = "点击解析后这里会输出结果";
|
||||
//
|
||||
// splitContainer1
|
||||
//
|
||||
splitContainer1.Dock = DockStyle.Fill;
|
||||
splitContainer1.Location = new Point(0, 0);
|
||||
splitContainer1.Margin = new Padding(2, 3, 2, 3);
|
||||
splitContainer1.Name = "splitContainer1";
|
||||
//
|
||||
// splitContainer1.Panel1
|
||||
//
|
||||
splitContainer1.Panel1.Controls.Add(tableLayoutPanel1);
|
||||
//
|
||||
// splitContainer1.Panel2
|
||||
//
|
||||
splitContainer1.Panel2.Controls.Add(dataGridView1);
|
||||
splitContainer1.Size = new Size(931, 382);
|
||||
splitContainer1.SplitterDistance = 457;
|
||||
splitContainer1.SplitterWidth = 3;
|
||||
splitContainer1.TabIndex = 4;
|
||||
//
|
||||
// tableLayoutPanel1
|
||||
//
|
||||
tableLayoutPanel1.ColumnCount = 1;
|
||||
tableLayoutPanel1.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50F));
|
||||
tableLayoutPanel1.Controls.Add(textBox1, 0, 0);
|
||||
tableLayoutPanel1.Controls.Add(textBox2, 0, 1);
|
||||
tableLayoutPanel1.Controls.Add(button1, 0, 2);
|
||||
tableLayoutPanel1.Controls.Add(flowLayoutPanel1, 0, 3);
|
||||
tableLayoutPanel1.Dock = DockStyle.Fill;
|
||||
tableLayoutPanel1.Location = new Point(0, 0);
|
||||
tableLayoutPanel1.Margin = new Padding(2, 3, 2, 3);
|
||||
tableLayoutPanel1.Name = "tableLayoutPanel1";
|
||||
tableLayoutPanel1.RowCount = 4;
|
||||
tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.Percent, 83.62069F));
|
||||
tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.Percent, 16.37931F));
|
||||
tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.Absolute, 49F));
|
||||
tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.Absolute, 46F));
|
||||
tableLayoutPanel1.Size = new Size(457, 382);
|
||||
tableLayoutPanel1.TabIndex = 4;
|
||||
//
|
||||
// flowLayoutPanel1
|
||||
//
|
||||
flowLayoutPanel1.Controls.Add(checkBox1);
|
||||
flowLayoutPanel1.Controls.Add(checkBox2);
|
||||
flowLayoutPanel1.Dock = DockStyle.Fill;
|
||||
flowLayoutPanel1.Location = new Point(3, 338);
|
||||
flowLayoutPanel1.Name = "flowLayoutPanel1";
|
||||
flowLayoutPanel1.Size = new Size(451, 41);
|
||||
flowLayoutPanel1.TabIndex = 4;
|
||||
//
|
||||
// checkBox1
|
||||
//
|
||||
checkBox1.AutoSize = true;
|
||||
checkBox1.Checked = true;
|
||||
checkBox1.CheckState = CheckState.Checked;
|
||||
checkBox1.Location = new Point(3, 3);
|
||||
checkBox1.Name = "checkBox1";
|
||||
checkBox1.Size = new Size(87, 21);
|
||||
checkBox1.TabIndex = 0;
|
||||
checkBox1.Text = "强制网页版";
|
||||
checkBox1.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// checkBox2
|
||||
//
|
||||
checkBox2.AutoSize = true;
|
||||
checkBox2.Checked = true;
|
||||
checkBox2.CheckState = CheckState.Checked;
|
||||
checkBox2.Location = new Point(96, 3);
|
||||
checkBox2.Name = "checkBox2";
|
||||
checkBox2.Size = new Size(123, 21);
|
||||
checkBox2.TabIndex = 1;
|
||||
checkBox2.Text = "解析完成自动打开";
|
||||
checkBox2.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// dataGridView1
|
||||
//
|
||||
dataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
dataGridView1.Dock = DockStyle.Fill;
|
||||
dataGridView1.Location = new Point(0, 0);
|
||||
dataGridView1.Margin = new Padding(2, 3, 2, 3);
|
||||
dataGridView1.Name = "dataGridView1";
|
||||
dataGridView1.RowHeadersWidth = 51;
|
||||
dataGridView1.RowTemplate.Height = 29;
|
||||
dataGridView1.Size = new Size(471, 382);
|
||||
dataGridView1.TabIndex = 0;
|
||||
//
|
||||
// Form1
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 17F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(931, 382);
|
||||
Controls.Add(splitContainer1);
|
||||
Margin = new Padding(2, 3, 2, 3);
|
||||
Name = "Form1";
|
||||
Text = "淘宝链接缩短工具";
|
||||
splitContainer1.Panel1.ResumeLayout(false);
|
||||
splitContainer1.Panel2.ResumeLayout(false);
|
||||
((System.ComponentModel.ISupportInitialize)splitContainer1).EndInit();
|
||||
splitContainer1.ResumeLayout(false);
|
||||
tableLayoutPanel1.ResumeLayout(false);
|
||||
tableLayoutPanel1.PerformLayout();
|
||||
flowLayoutPanel1.ResumeLayout(false);
|
||||
flowLayoutPanel1.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)dataGridView1).EndInit();
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private Button button1;
|
||||
private TextBox textBox1;
|
||||
private TextBox textBox2;
|
||||
private SplitContainer splitContainer1;
|
||||
private TableLayoutPanel tableLayoutPanel1;
|
||||
private DataGridView dataGridView1;
|
||||
private FlowLayoutPanel flowLayoutPanel1;
|
||||
private CheckBox checkBox1;
|
||||
private CheckBox checkBox2;
|
||||
private DataGridViewTextBoxColumn 参数名称;
|
||||
private DataGridViewTextBoxColumn 参数内容;
|
||||
}
|
||||
}
|
136
淘宝网址解析/Form1.cs
Normal file
136
淘宝网址解析/Form1.cs
Normal file
|
@ -0,0 +1,136 @@
|
|||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace 淘宝网址解析
|
||||
{
|
||||
public partial class Form1 : Form
|
||||
{
|
||||
public Form1()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
static Dictionary<string, string> 淘宝网站 = new Dictionary<string, string>
|
||||
{
|
||||
["淘宝网页版"] = "item.taobao.com",
|
||||
["淘宝手机版"] = "m.taobao.com",
|
||||
["淘宝手机版new"] = "new.m.taobao.com",
|
||||
["淘宝短网址"] = "m.tb.cn",
|
||||
["天猫网址"] = "detail.tmall.com",
|
||||
["天猫超市"] = "chaoshi.detail.tmall.com",
|
||||
};
|
||||
BindingList<网址参数> 参数列表 = new();
|
||||
private async void button1_ClickAsync(object sender, EventArgs e)
|
||||
{
|
||||
//清空参数列表
|
||||
参数列表.Clear();
|
||||
string temp = "";
|
||||
//取出完整网址
|
||||
try
|
||||
{
|
||||
temp = textBox1.Text.Substring(textBox1.Text.IndexOf("http"));
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
MessageBox.Show("请输入正确的网址,例如https://detail.tmall.com/item.htm?id=640330331740");
|
||||
return;
|
||||
}
|
||||
|
||||
temp = temp.Split(' ')[0];
|
||||
|
||||
//解析链接
|
||||
var 网页域名 = "";
|
||||
var 网站页面 = "";
|
||||
try
|
||||
{
|
||||
网页域名 = temp.Split('/')[2];
|
||||
网站页面 = temp.Split('/')[3].Split('?')[0];
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
MessageBox.Show("网址可能不是太正确...");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (网页域名 == 淘宝网站["淘宝短网址"])
|
||||
{
|
||||
//解析短网址
|
||||
temp = await 解析短网址(temp);
|
||||
temp = temp.Substring(textBox1.Text.IndexOf("http"));
|
||||
temp = temp.Split(' ')[0];
|
||||
}
|
||||
if (checkBox1.Checked) if (网页域名 == 淘宝网站["淘宝手机版new"] || 网页域名 == 淘宝网站["淘宝手机版"])
|
||||
{
|
||||
网页域名 = 淘宝网站["淘宝网页版"];
|
||||
网站页面 = @"item.htm";
|
||||
}
|
||||
|
||||
var 结果网址 = $"https://{网页域名}/{网站页面}?";
|
||||
temp = temp.Substring(temp.IndexOf("htm?") + 4);
|
||||
var 参数 = temp.Split("&");
|
||||
bool 找到id = false;
|
||||
foreach (var item in 参数)
|
||||
{
|
||||
var 参数与内容 = item.Split("=");
|
||||
参数列表.Add(new 网址参数 { 参数名称 = 参数与内容[0], 参数内容 = 参数与内容[1] });
|
||||
if (参数与内容[0] == "id")
|
||||
{
|
||||
结果网址 += $"{参数与内容[0]}={参数与内容[1]}";
|
||||
找到id = true;
|
||||
}
|
||||
}
|
||||
if(找到id == false) { MessageBox.Show("未找到宝贝id!结果大概率是寄了","可恶!"); }
|
||||
dataGridView1.DataSource = 参数列表;
|
||||
dataGridView1.Columns[0].AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells;
|
||||
dataGridView1.Columns[1].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||
textBox2.Text = 结果网址;
|
||||
if (checkBox2.Checked)
|
||||
{
|
||||
Process.Start(new ProcessStartInfo()
|
||||
{
|
||||
FileName = 结果网址,
|
||||
UseShellExecute = true
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static HttpClient http客户端 = new();
|
||||
private async Task<string> 解析短网址(string 网址)
|
||||
{
|
||||
try
|
||||
{
|
||||
HttpResponseMessage response = await http客户端.GetAsync(网址);
|
||||
response.EnsureSuccessStatusCode();
|
||||
string responseBody = await response.Content.ReadAsStringAsync();
|
||||
// Above three lines can be replaced with new helper method below
|
||||
// string responseBody = await client.GetStringAsync(uri);
|
||||
var aa = responseBody.Substring(responseBody.IndexOf(@"var url = 'https://new.m.taobao.com"));
|
||||
aa = aa.Substring(0, aa.IndexOf('\'', aa.IndexOf('\'') + 1));
|
||||
aa = aa.Replace(@"var url = '", "").Replace(@"'", "");
|
||||
return aa;
|
||||
|
||||
}
|
||||
catch (HttpRequestException e)
|
||||
{
|
||||
Debug.WriteLine("\nException Caught!");
|
||||
Debug.WriteLine("Message :{0} ", e.Message);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public class 网址参数
|
||||
{
|
||||
public string 参数名称 { get; set; }
|
||||
public string 参数内容 { get; set; }
|
||||
|
||||
}
|
||||
|
||||
private void button2_Click(object sender, EventArgs e)
|
||||
{
|
||||
http客户端.BaseAddress = new Uri($"https://{淘宝网站["淘宝短网址"]}");
|
||||
|
||||
}
|
||||
}
|
||||
}
|
60
淘宝网址解析/Form1.resx
Normal file
60
淘宝网址解析/Form1.resx
Normal file
|
@ -0,0 +1,60 @@
|
|||
<root>
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
17
淘宝网址解析/Program.cs
Normal file
17
淘宝网址解析/Program.cs
Normal file
|
@ -0,0 +1,17 @@
|
|||
namespace 淘宝网址解析
|
||||
{
|
||||
internal static class Program
|
||||
{
|
||||
/// <summary>
|
||||
/// The main entry point for the application.
|
||||
/// </summary>
|
||||
[STAThread]
|
||||
static void Main()
|
||||
{
|
||||
// To customize application configuration such as set high DPI settings or default font,
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(new Form1());
|
||||
}
|
||||
}
|
||||
}
|
11
淘宝网址解析/淘宝网址解析.csproj
Normal file
11
淘宝网址解析/淘宝网址解析.csproj
Normal file
|
@ -0,0 +1,11 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>net7.0-windows</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<UseWindowsForms>true</UseWindowsForms>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
Loading…
Reference in New Issue
Block a user