Alte Quellcode bestand wiederhergestellt

This commit is contained in:
Damian Wessels
2024-08-28 17:15:53 +02:00
parent 6c216ca189
commit b566b0a201
5 changed files with 115 additions and 51 deletions

View File

@@ -1,10 +1,12 @@
// See https://aka.ms/new-console-template for more information
using OpenQA.Selenium.Chrome;
using SeleniumUndetectedChromeDriver;
using OpenQA.Selenium;
using System.Net;
using System.Diagnostics;
using ConsoleApp3.Contracts;
using static System.Collections.Specialized.BitVector32;
namespace CardmarketBot
{
@@ -31,19 +33,44 @@ namespace CardmarketBot
public List<Kunde> ParseCardMarket(string forceid = "")
{
//var driver = UndetectedChromeDriver.Create(driverExecutablePath: await new ChromeDriverInstaller().Auto());
ChromeOptions options = new ChromeOptions();
options.AddArgument("start-maximized");
options.AddArgument("incognito");
options.AddArgument("disable-popup-blocking");
//options.AddArgument("incognito");
//options.AddArgument("disable-popup-blocking");
options.AddArgument("force-device-scale-factor=0.8");
IWebDriver cd = new ChromeDriver(options);
//driver.GoToUrl("https://www.cardmarket.com/de/OnePiece");
cd.Url = @"https://www.cardmarket.com/de/OnePiece";
cd.Navigate();
cd.FindElement(By.CssSelector("#CookiesConsent > div > div > form > button")).Click();
Thread.Sleep(10);
Thread.Sleep(2000);
IWebElement? element;
/*
bool cloudfire = true;
if (cloudfire)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Scheint als würde Cloudfire aktiviert sein.");
Console.WriteLine("Bitte bestätige und komme zurück und klicke die buchstabe c und Enter");
Console.ReadLine();
}
*/
cd.FindElement(By.CssSelector("#CookiesConsent > div > div > form > div > button")).Click();
Thread.Sleep(2000);
cd.FindElement(By.Name("username")).Click();
cd.FindElement(By.Name("username")).SendKeys(username);
@@ -52,6 +79,8 @@ namespace CardmarketBot
cd.FindElement(By.CssSelector("#header-login > input.btn.btn-outline-primary.btn-sm")).Click();
Thread.Sleep(6000);
CookieContainer cookieContainer = new CookieContainer();
foreach (var c in cd.Manage().Cookies.AllCookies)
@@ -63,11 +92,47 @@ namespace CardmarketBot
List<string> ids = new List<string>();
List<Kunde> kunden = new List<Kunde>();
IWebElement element;
//IWebElement? element;
/*cloudfire = true;
try
{
element = cd.FindElement(By.XPath("/html/body/div[1]/div/div[1]/div"));
// //[@id="challenge-body-text"]
}
catch (NoSuchElementException)
{
cloudfire = false;
}
Console.WriteLine(cloudfire);
if(cloudfire )
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Scheint als würde Cloudfire aktiviert sein.");
Console.WriteLine("Bitte bestätige und komme zurück und klicke die buchstabe c und Enter");
Console.ReadLine();
}
*/
if (forceid != "")
{
ids.Add(forceid);
string[] mid = forceid.Split(',');
if (mid.Length < 0)
{
ids.Add(forceid);
}
else
{
foreach(string kid in mid)
{
ids.Add(kid);
}
}
}
else
{
@@ -75,15 +140,16 @@ namespace CardmarketBot
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)
var verkaufstable = cd.FindElements(By.XPath("/html/body/main/section/div[3]/div[4]/div[2]/*"));
foreach(var karte in verkaufstable)
{
ids.Add(datas[i]);
var content = karte.Text.Split("\r\n");
// 10 Stellen ist die ID
ids.Add(content[1]);
}
}
catch (OpenQA.Selenium.NotFoundException)
{