Projektdateien hinzufügen.
This commit is contained in:
parent
3d29683337
commit
737f9cd6e3
25
webCrawlerGoogle.sln
Normal file
25
webCrawlerGoogle.sln
Normal file
@ -0,0 +1,25 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.10.35122.118
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "webCrawlerGoogle", "webCrawlerGoogle\webCrawlerGoogle.csproj", "{36E507D2-6D2C-43DD-9E30-F7E151018942}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{36E507D2-6D2C-43DD-9E30-F7E151018942}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{36E507D2-6D2C-43DD-9E30-F7E151018942}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{36E507D2-6D2C-43DD-9E30-F7E151018942}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{36E507D2-6D2C-43DD-9E30-F7E151018942}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {FB32F52A-3116-4EB2-A3D9-B6435A5B7A2E}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
97
webCrawlerGoogle/Form1.Designer.cs
generated
Normal file
97
webCrawlerGoogle/Form1.Designer.cs
generated
Normal file
@ -0,0 +1,97 @@
|
||||
namespace webCrawlerGoogle
|
||||
{
|
||||
partial class Form1
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.txtCategory = new System.Windows.Forms.TextBox();
|
||||
this.txtCity = new System.Windows.Forms.TextBox();
|
||||
this.btnSearch = new System.Windows.Forms.Button();
|
||||
this.lstResults = new System.Windows.Forms.ListBox();
|
||||
this.SuspendLayout();
|
||||
|
||||
//
|
||||
// txtCategory
|
||||
//
|
||||
this.txtCategory.Location = new System.Drawing.Point(12, 12);
|
||||
this.txtCategory.Name = "txtCategory";
|
||||
this.txtCategory.Size = new System.Drawing.Size(260, 20);
|
||||
this.txtCategory.TabIndex = 0;
|
||||
this.txtCategory.PlaceholderText = "Rubrik (z.B. Restaurant)";
|
||||
|
||||
//
|
||||
// txtCity
|
||||
//
|
||||
this.txtCity.Location = new System.Drawing.Point(12, 38);
|
||||
this.txtCity.Name = "txtCity";
|
||||
this.txtCity.Size = new System.Drawing.Size(260, 20);
|
||||
this.txtCity.TabIndex = 1;
|
||||
this.txtCity.PlaceholderText = "Stadt (z.B. Berlin)";
|
||||
|
||||
//
|
||||
// btnSearch
|
||||
//
|
||||
this.btnSearch.Location = new System.Drawing.Point(12, 64);
|
||||
this.btnSearch.Name = "btnSearch";
|
||||
this.btnSearch.Size = new System.Drawing.Size(260, 23);
|
||||
this.btnSearch.TabIndex = 2;
|
||||
this.btnSearch.Text = "Suchen";
|
||||
this.btnSearch.UseVisualStyleBackColor = true;
|
||||
this.btnSearch.Click += new System.EventHandler(this.btnSearch_Click);
|
||||
|
||||
//
|
||||
// lstResults
|
||||
//
|
||||
this.lstResults.FormattingEnabled = true;
|
||||
this.lstResults.Location = new System.Drawing.Point(12, 93);
|
||||
this.lstResults.Name = "lstResults";
|
||||
this.lstResults.Size = new System.Drawing.Size(260, 147);
|
||||
this.lstResults.TabIndex = 3;
|
||||
|
||||
//
|
||||
// Form1
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(284, 261);
|
||||
this.Controls.Add(this.lstResults);
|
||||
this.Controls.Add(this.btnSearch);
|
||||
this.Controls.Add(this.txtCity);
|
||||
this.Controls.Add(this.txtCategory);
|
||||
this.Name = "Form1";
|
||||
this.Text = "Google Business Suche";
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
private System.Windows.Forms.TextBox txtCategory;
|
||||
private System.Windows.Forms.TextBox txtCity;
|
||||
private System.Windows.Forms.Button btnSearch;
|
||||
private System.Windows.Forms.ListBox lstResults;
|
||||
}
|
||||
}
|
||||
101
webCrawlerGoogle/Form1.cs
Normal file
101
webCrawlerGoogle/Form1.cs
Normal file
@ -0,0 +1,101 @@
|
||||
using MySql.Data.MySqlClient;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using static System.Windows.Forms.VisualStyles.VisualStyleElement.ListView;
|
||||
|
||||
namespace webCrawlerGoogle
|
||||
{
|
||||
public partial class Form1 : Form
|
||||
{
|
||||
private const string ApiKey = "AIzaSyCjdysuuyc2bs4ikqT8xyIpPJHiDZ4CEo4"; // Füge hier deinen API-Schlüssel ein
|
||||
private string connectionString = "Server=192.168.178.201;Database=domainchecker;User ID=root;Password=1td5rugut8;";
|
||||
|
||||
public Form1()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private async void btnSearch_Click(object sender, EventArgs e)
|
||||
{
|
||||
string category = txtCategory.Text;
|
||||
string city = txtCity.Text;
|
||||
|
||||
if (string.IsNullOrEmpty(category) || string.IsNullOrEmpty(city))
|
||||
{
|
||||
MessageBox.Show("Bitte sowohl eine Rubrik als auch eine Stadt eingeben.");
|
||||
return;
|
||||
}
|
||||
|
||||
string requestUri = $"https://maps.googleapis.com/maps/api/place/textsearch/json?query={category}+in+{city}&key={ApiKey}";
|
||||
|
||||
using (HttpClient client = new HttpClient())
|
||||
{
|
||||
HttpResponseMessage response = await client.GetAsync(requestUri);
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
string jsonResult = await response.Content.ReadAsStringAsync();
|
||||
JObject result = JObject.Parse(jsonResult);
|
||||
|
||||
lstResults.Items.Clear();
|
||||
|
||||
foreach (var place in result["results"])
|
||||
{
|
||||
string website = await GetPlaceDetails((string)place["place_id"]);
|
||||
if (!string.IsNullOrEmpty(website))
|
||||
{
|
||||
lstResults.Items.Add(website);
|
||||
SaveToDatabase(website);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Fehler bei der Anfrage: " + response.StatusCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<string> GetPlaceDetails(string placeId)
|
||||
{
|
||||
string requestUri = $"https://maps.googleapis.com/maps/api/place/details/json?place_id={placeId}&fields=website&key={ApiKey}";
|
||||
|
||||
using (HttpClient client = new HttpClient())
|
||||
{
|
||||
HttpResponseMessage response = await client.GetAsync(requestUri);
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
string jsonResult = await response.Content.ReadAsStringAsync();
|
||||
JObject result = JObject.Parse(jsonResult);
|
||||
|
||||
return (string)result["result"]["website"];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private void SaveToDatabase(string website)
|
||||
{
|
||||
using (MySqlConnection conn = new MySqlConnection(connectionString))
|
||||
{
|
||||
conn.Open();
|
||||
string queryCheck = "SELECT COUNT(*) FROM webCrawler WHERE webseite = @website";
|
||||
using (MySqlCommand cmdCheck = new MySqlCommand(queryCheck, conn))
|
||||
{
|
||||
cmdCheck.Parameters.AddWithValue("@website", website);
|
||||
int count = Convert.ToInt32(cmdCheck.ExecuteScalar());
|
||||
|
||||
if (count == 0)
|
||||
{
|
||||
string queryInsert = "INSERT INTO webCrawler (webseite) VALUES (@website)";
|
||||
using (MySqlCommand cmdInsert = new MySqlCommand(queryInsert, conn))
|
||||
{
|
||||
cmdInsert.Parameters.AddWithValue("@website", website);
|
||||
|
||||
cmdInsert.ExecuteNonQuery();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
120
webCrawlerGoogle/Form1.resx
Normal file
120
webCrawlerGoogle/Form1.resx
Normal file
@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
||||
17
webCrawlerGoogle/Program.cs
Normal file
17
webCrawlerGoogle/Program.cs
Normal file
@ -0,0 +1,17 @@
|
||||
namespace webCrawlerGoogle
|
||||
{
|
||||
internal static class Program
|
||||
{
|
||||
/// <summary>
|
||||
/// The main entry point for the application.
|
||||
/// </summary>
|
||||
[STAThread]
|
||||
static void Main()
|
||||
{
|
||||
// To customize application configuration such as set high DPI settings or default font,
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(new Form1());
|
||||
}
|
||||
}
|
||||
}
|
||||
16
webCrawlerGoogle/webCrawlerGoogle.csproj
Normal file
16
webCrawlerGoogle/webCrawlerGoogle.csproj
Normal file
@ -0,0 +1,16 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>net8.0-windows</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<UseWindowsForms>true</UseWindowsForms>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="MySql.Data" Version="9.0.0" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
Loading…
Reference in New Issue
Block a user