Renaming
start.bat added
This commit is contained in:
132
CardMarketBot/CardMarketParser.cs
Normal file
132
CardMarketBot/CardMarketParser.cs
Normal file
@@ -0,0 +1,132 @@
|
||||
// See https://aka.ms/new-console-template for more information
|
||||
|
||||
using OpenQA.Selenium.Chrome;
|
||||
using OpenQA.Selenium;
|
||||
using System.Net;
|
||||
using System.Diagnostics;
|
||||
using ConsoleApp3.Contracts;
|
||||
|
||||
namespace CardmarketBot
|
||||
{
|
||||
class CardMarketParser
|
||||
{
|
||||
private readonly string username;
|
||||
private readonly string password;
|
||||
|
||||
Dictionary<string, Helper.Porto> portoberechnung = new Dictionary<string, Helper.Porto>()
|
||||
{
|
||||
{"1,15 €", Helper.Porto.BRIEF085 },
|
||||
{"1,30 €", Helper.Porto.BRIEF100 },
|
||||
{"2,10 €", Helper.Porto.BRIEF160 },
|
||||
{"3,25 €", Helper.Porto.BRIEF275 },
|
||||
{"2,60 €", Helper.Porto.PRIO210 },
|
||||
{"3,20 €", Helper.Porto.PRIO270 },
|
||||
};
|
||||
|
||||
public CardMarketParser(string username, string password)
|
||||
{
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public List<Kunde> ParseCardMarket()
|
||||
{
|
||||
ChromeOptions options = new ChromeOptions();
|
||||
options.AddArgument("start-maximized");
|
||||
IWebDriver cd = new ChromeDriver(options);
|
||||
cd.Url = @"https://www.cardmarket.com/de/OnePiece";
|
||||
|
||||
cd.Navigate();
|
||||
|
||||
cd.FindElement(By.CssSelector("#CookiesConsent > div > div > form > button")).Click();
|
||||
Thread.Sleep(10);
|
||||
cd.FindElement(By.Name("username")).Click();
|
||||
cd.FindElement(By.Name("username")).SendKeys(username);
|
||||
|
||||
cd.FindElement(By.Name("userPassword")).Click();
|
||||
cd.FindElement(By.Name("userPassword")).SendKeys(password);
|
||||
|
||||
cd.FindElement(By.CssSelector("#header-login > input.btn.btn-outline-primary.btn-sm")).Click();
|
||||
|
||||
|
||||
CookieContainer cookieContainer = new CookieContainer();
|
||||
foreach (var c in cd.Manage().Cookies.AllCookies)
|
||||
{
|
||||
string name = c.Name;
|
||||
string value = c.Value;
|
||||
cookieContainer.Add(new System.Net.Cookie(name, value, c.Path, c.Domain));
|
||||
}
|
||||
|
||||
cd.Navigate().GoToUrl(@"https://www.cardmarket.com/de/OnePiece/Orders/Sales/Paid");
|
||||
//cd.Navigate().GoToUrl(@"https://www.cardmarket.com/de/OnePiece/Orders/Sales/Sent");
|
||||
|
||||
List<string> ids = new List<string>();
|
||||
List<Kunde> kunden = new List<Kunde>();
|
||||
|
||||
IWebElement element;
|
||||
try
|
||||
{
|
||||
element = cd.FindElement(By.XPath("/html/body/main/section/div[3]/div[4]"));
|
||||
|
||||
string content = element.Text;
|
||||
|
||||
|
||||
string[] datas = content.Split("\r\n");
|
||||
|
||||
|
||||
for (int i = 8; i < datas.Length; i += 7)
|
||||
{
|
||||
ids.Add(datas[i]);
|
||||
}
|
||||
}
|
||||
catch(OpenQA.Selenium.NotFoundException)
|
||||
{
|
||||
Console.WriteLine("Keine Verkäufe aktuell");
|
||||
return kunden;
|
||||
}
|
||||
|
||||
foreach (string id in ids)
|
||||
{
|
||||
//if (id != "1121844928") continue;
|
||||
//Console.WriteLine(id);
|
||||
cd.Navigate().GoToUrl(string.Format(@"https://www.cardmarket.com/de/OnePiece/Orders/{0}", id));
|
||||
element = cd.FindElement(By.XPath("/html/body/main/section/div/div[1]/div/div[3]/div[2]/div[2]/div/div"));
|
||||
|
||||
Kunde kunde = Helper.ConvertToKunde(element.Text);
|
||||
|
||||
// Bezahldatum
|
||||
element = cd.FindElement(By.XPath("/html/body/main/section/div/div[1]/div/div[2]/div/div[2]/div[2]"));
|
||||
kunde.Bezahldatum = Helper.ConvertBezahlDatum(element.Text);
|
||||
|
||||
|
||||
// Versandkosten
|
||||
element = cd.FindElement(By.XPath("/html/body/main/section/div/div[1]/div/div[3]/div[1]/div[2]/div/div[3]/span[2]"));
|
||||
Helper.Porto resul;
|
||||
if(portoberechnung.TryGetValue(element.Text, out resul))
|
||||
{
|
||||
kunde.Versandskosten = resul;
|
||||
}
|
||||
else
|
||||
{
|
||||
kunde.OverrideVersandskosten = element.Text;
|
||||
Console.WriteLine($"Achtung bei ID {id} wurde kein Richtige Porto berechnet. Liegt es im Ausland?");
|
||||
}
|
||||
//kunde.Versandskosten = portoberechnung[element.Text];
|
||||
kunde.BestellungID = id;
|
||||
|
||||
|
||||
|
||||
// Artikeln
|
||||
element = cd.FindElement(By.XPath("/html/body/main/section/div/div[1]/div/div[5]/table/tbody"));
|
||||
string artikeln = element.Text;
|
||||
kunde.Artikels = Helper.ParseArtikeln(element.Text);
|
||||
|
||||
|
||||
kunden.Add(kunde);
|
||||
Thread.Sleep(TimeSpan.FromSeconds(3));
|
||||
}
|
||||
cd.Quit();
|
||||
return kunden;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user