SubTaobaoLongLink/淘宝网址解析/Form1.cs

136 lines
4.9 KiB
C#
Raw Normal View History

2023-03-11 00:08:21 +08:00
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://{淘宝网站[""]}");
}
}
}