120 lines
4.2 KiB
C#
120 lines
4.2 KiB
C#
// See https://aka.ms/new-console-template for more information
|
|
|
|
using OpenQA.Selenium.Chrome;
|
|
using OpenQA.Selenium;
|
|
using System.Net;
|
|
|
|
/*
|
|
*
|
|
* referalPage: /de/OnePiece
|
|
username: Skywalkerex
|
|
userPassword: Magnatpower310!!
|
|
/de/OnePiece/PostGetAction/User_Login
|
|
|
|
curbpJUJmtup1t.Tq0awbHIhIRwhzMW7vrsWxLAJu.pI9X4r
|
|
*/
|
|
|
|
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.AB-login-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");
|
|
|
|
IWebElement element = cd.FindElement(By.XPath("/html/body/main/section/div[3]/div[3]/div[2]"));
|
|
string content = element.Text;
|
|
|
|
string[] datas = content.Split("\r\n");
|
|
|
|
List<string> ids = new List<string>();
|
|
for (int i = 0; i < datas.Length; i += 7)
|
|
{
|
|
ids.Add(datas[i]);
|
|
}
|
|
|
|
List<Kunde> kunden = new List<Kunde>();
|
|
|
|
int maxCounter = 2;
|
|
int counter = 0;
|
|
foreach (string id in ids)
|
|
{
|
|
if (counter > maxCounter) break;
|
|
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 = element.Text;
|
|
//Debugger.Break();
|
|
|
|
// 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]"));
|
|
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);
|
|
counter++;
|
|
Thread.Sleep(TimeSpan.FromSeconds(5));
|
|
}
|
|
return kunden;
|
|
}
|
|
}
|
|
} |