Skip to content

Commit

Permalink
Fix for Issues #36 and #34
Browse files Browse the repository at this point in the history
Tried to make changes to the things said. Scrape now returns the Result of it.

And the Interfaces, Model and Scraper should all have the corresponding Namespaces. Thanks. Feel free to make any changes regarding this topic if not fixed completly.
  • Loading branch information
realTobby committed Nov 21, 2018
1 parent e2606fa commit cd2f5d2
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 42 deletions.
16 changes: 2 additions & 14 deletions ImageScraperGUI/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,8 @@
using LibImageScraper;
using LibImageScraper.Logic;
using LibImageScraper.Models;
using System;
using LibImageScraper.Scrapers;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace ImageScraperGUI
{
Expand All @@ -37,7 +25,7 @@ private void Button_Click(object sender, RoutedEventArgs e)
IMAGESCRAPER.SetSource(textBoxUrl.Text);

IMAGESCRAPER.Scrape();
List<Dump> result = IMAGESCRAPER.ReturnResult();
List<Dump> result = IMAGESCRAPER.ReturnDump();
foreach(var item in result)
{
listBoxResult.Items.Add(item.Path);
Expand Down
10 changes: 3 additions & 7 deletions LibImageScraper/Interfaces/IScraper.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections.Generic;

namespace LibImageScraper.Interfaces
namespace LibImageScraper
{
public interface IScraper
{
// Gives the Scraper a source to work with (ex: a path or a url)
void SetSource(string source);

// Starts the scraping process
void Scrape();
List<Dump> Scrape();


}
Expand Down
2 changes: 1 addition & 1 deletion LibImageScraper/LibImageScraper.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Interfaces\IScraper.cs" />
<Compile Include="Logic\OnlineHTMLScraper.cs" />
<Compile Include="Scrapers\OnlineHTMLScraper.cs" />
<Compile Include="Models\Dump.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
Expand Down
8 changes: 1 addition & 7 deletions LibImageScraper/Models/Dump.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LibImageScraper.Models
namespace LibImageScraper
{
public class Dump
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
using HtmlAgilityPack;
using LibImageScraper.Interfaces;
using LibImageScraper.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;

namespace LibImageScraper.Logic
namespace LibImageScraper.Scrapers
{
public class OnlineHTMLScraper : IScraper
{
Expand All @@ -23,23 +17,23 @@ public OnlineHTMLScraper(string url)
SetSource(url);
}



public void SetSource(string source)
{
URL = source;
}

public void Scrape()
public List<Dump> Scrape()
{
urlDump.Clear();

var web = new HtmlWeb();
System.Net.ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls12;
var document = web.Load(URL);
HtmlNodeCollection imgs = document.DocumentNode.SelectNodes("//img[@src]");
if (imgs == null)
{
urlDump.Add(new Dump("no images found"));
return;
return urlDump;
}

foreach (HtmlNode img in imgs)
Expand All @@ -54,10 +48,10 @@ public void Scrape()
urlDump.Add(new Dump( URL + src.Value));
}


return urlDump;
}

public List<Dump> ReturnResult()
public List<Dump> ReturnDump()
{
return urlDump;
}
Expand Down

0 comments on commit cd2f5d2

Please sign in to comment.