C# 配列と構造体

using System;

struct Simple
{
public int Number;
public string Name;

public Simple(int n,string s)
{
    Number = n;
    Name = s;
}

}

class MainClass
{
static void Main()
{
Simple s1 = new Simple();

    Console.WriteLine(s1.Number);
    Console.WriteLine(s1.Name);

    Simple s2 = new Simple(1, "testname");

    Console.WriteLine(s2.Number);
    Console.WriteLine(s2.Name);

    Simple ss;
}

}

C# 配列

using System;

namespace array3
{
internal class Program
{
static void Main(string[] args)
{
string[] weekDays =
{ “sun”, “Mon”, “Tue” , “Wed”, “Thu”, “Fri” , “Sat”};

        for(int i = 0; i < weekDays.Length; i++)
        {
            Console.WriteLine(weekDays[i]);
        }

        foreach(string s in weekDays)
        {
            Console.WriteLine(s);
        }

        int[] a = { 1, 2, 3 };
        int sum = 0;
        for(int i = 0; i < a.Length; i++)
        {
            sum += a[i];
        }
        Console.WriteLine(sum);
    }
}

}

Python Webcrawler

import requests
from bs4 import BeautifulSoup

def crawl(url, max_depth=2):
if max_depth < 0:
return

try:
response = requests.get(url)
content = response.content
soup = BeautifulSoup(content, ‘html.parser’)

links = set()

for link in soup.find_all(‘a’):
href = link.get(‘href’)
if href and href.startswith(‘http’):
links.add(href)

print(f”Found {len(links)} links at {url}”)

for link in links:
crawl(link, max_depth – 1)

except requests.RequestException as e:
print(f”Error during requests to {url} : {str(e)}”)

# 使用例
start_url = “https://b.hatena.ne.jp/” # スタートするURL
crawl(start_url, max_depth=2) # 深さ2でクロール