bingから画像を一括ダウンロードするアプリ。

2020.06.14

Logging

任意のキーワード検索でbing画像からを一括ダウンロードするアプリを作りました。img-dl-bing-sss.exeファイルを起動すると動画のようなコンソール画面が開くので入力してダウンロードを開始してください。ダウンロードが終わると勝手に閉じます。

なお、一応R指定にも対応しています、キーワードがR指定項目かもと思う場合、Yと入力ください。
新垣結衣さんの熱烈なファンでもないですが、綺麗な方だとは思います。ということで例として使用させて頂きました、、、関係者の皆様ごめんなさい。

bingから画像を一括ダウンロードするアプリ

このアプリはウィンドウズ10環境で動作します。また、動作しないブロックされる場合は下記のURL等を参照しブロックを解除しお使いください。ブロック解除方法:https://forest.watch.impress.co.jp/docs/news/1130655.html

※なお、Bingサイトのデザインが変わった場合、動作しなくなりますのであしからず。

画像ダウンロードアプリのソースコードはこちら(古いコードですので動かない場合がありますVS2019C#)

using System;
using System.Runtime.CompilerServices;

namespace img_dl_bing_sss
{
    class Program
    {
        static void Main(string[] args)
        {
            string keyword = "",R18="";
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine("処理中は画面や立ち上がったブラウザを閉じないでください。\n" +
                "処理が完了すると「***終了します***」と表示されます。\n" +
                "何かキーを押し終了してください\n\n");


            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("↓検索キーワードを入力しエンターを押してください");
            keyword = Console.ReadLine();
            Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine("↓R指定ですか?\nY or N かの文字を入力しエンターを押してください");
            R18 = Console.ReadLine();
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine("***画像のダウンロード量(画像数ではありません) 1?999 ***");
            var scroll = 9999;
            try
            {
                scroll = int.Parse(Console.ReadLine());
                if(scroll >=1 && scroll <= 999)
                {
                    scroll = scroll * 9999;
                }
            }
            catch
            {
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine("***検索キーワードが不適切です。***");
            }
            SuiteTests img =  new SuiteTests();
            if (img.Imgdlok(keyword, R18, scroll))
            {
                img.Dispose();
            }
            else {
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine("***検索キーワードが不適切です。***");
            }
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine("***終了します***");
            
        }
    }
}
// Generated by Selenium IDE
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.Remote;
using OpenQA.Selenium.Support.UI;
using OpenQA.Selenium.Interactions;
using Xunit;
using AngleSharp;
using AngleSharp.Html.Parser;
using AngleSharp.Html.Dom;
using AngleSharp.Dom;
using System.Runtime.InteropServices;
using Newtonsoft.Json;
using System.IO;
using System.Net;

public class SuiteTests : IDisposable {
  public IWebDriver driver {get; private set;}
  public IDictionary<String, Object> vars {get; private set;}
  public IJavaScriptExecutor js {get; private set;}
  public SuiteTests()
  {
    driver = new ChromeDriver();
    js = (IJavaScriptExecutor)driver;
    vars = new Dictionary<String, Object>();
  }
  public void Dispose()
  {
    driver.Quit();
  }
  public bool Imgdlok(string keyword="", string R18= "",int scroll = 999999)
    {
        if (keyword == "") return false;
        Console.Clear();
        string path = System.IO.Directory.GetCurrentDirectory() + "\\IMG\\";
        if (!Directory.Exists(path))
        {
            Directory.CreateDirectory(path);
        }
        driver.Navigate().GoToUrl("https://www.bing.com/?scope=images&nr=1&FORM=NOFORM");
        driver.Manage().Window.Size = new System.Drawing.Size(945, 1030);
        driver.FindElement(By.Id("sb_form_q")).Click();
        driver.FindElement(By.Id("sb_form_q")).SendKeys(keyword);
        driver.FindElement(By.CssSelector(".search.icon.tooltip")).Click();
        try
        {
            if (R18 == "Y")
        {
            driver.FindElement(By.LinkText("設定の変更")).Click();
            driver.FindElement(By.CssSelector("#settings_safesearch div:nth-child(3)")).Click();
            driver.FindElement(By.Id("adlt_set_off")).Click();
            driver.FindElement(By.Id("sv_btn")).Click();
            driver.FindElement(By.Id("adlt_confirm")).Click();
        }
        }
        catch
        {
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine("***R指定ではありません***");
        }
        try
        {
            double ps = 0;
                for (int i = 99; i < scroll;i+=1000)
            {

                js.ExecuteScript("window.scrollTo(0," + i + ")");
                Console.CursorLeft = 0;
                ps = (double)(((double)i / (double)scroll) * 100);
                Console.Write("処理中::{0:D2}%",(int)ps);
            }
        }
        catch
        {
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine("***Max画像まで到達しました***");
        }
        Console.ForegroundColor = ConsoleColor.White;
        Console.WriteLine("\n***ダウンロード処理開始***\n");
        int cnt = 0;
        var elm = driver.FindElements(By.ClassName("iusc"));
        driver.Manage().Window.Minimize();
        foreach (var e in elm) {
           dynamic jsondata = JsonConvert.DeserializeObject(e.GetAttribute("m"));
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine((string)jsondata.murl + "::wait.....");
            string imgurl = (string)jsondata.murl;
            if(4 <= Path.GetExtension(imgurl).Length && Path.GetExtension(imgurl).Length <= 5)
            {
                try
                {
                    cnt++;
                    string ext = Path.GetExtension(imgurl);
                    WebClient myWebClient = new WebClient();
                    myWebClient.DownloadFile(imgurl, path + "No-" + cnt + "-" + keyword + ext);
                    myWebClient.Dispose();
                    Console.ForegroundColor = ConsoleColor.Cyan;
                    Console.WriteLine("***" + cnt +"::" + imgurl + "\n::ダウンロード中、画面を閉じないでください...***");
                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.WriteLine("***" + cnt + "::ダウンロード済***");
                }
                catch
                {
                    Console.ForegroundColor = ConsoleColor.Yellow;
                    Console.WriteLine("***ダウンロードが失敗しました***");
                }

            }else{
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine("***画像の拡張子が不明のためダウンロードが失敗しました***");
            }
        }
        Console.ForegroundColor = ConsoleColor.Blue;
        Console.WriteLine("***ダウンロード完了しました***\n" + path);
        return true;
  }
}

タグ

10, bing, exe, img-dl-bing-sss, url, VS, アプリ, ウィンドウズ, キーワード, コード, こちら, こと, コンソール, サイト, ソース, ダウンロード, デザイン, ファイル, ファン, ブロック, 一括, 下記, 任意, 使用, , 入力, 動作, 動画, 勝手, 参照, 場合, 対応, 指定, 新垣結衣, , 方法, 検索, 環境, 画像, 画面, 皆様, , 綺麗, 解除, 起動, 開始, 関係者, 項目,

ブラウザのプッシュ通知が簡単にできちゃうFirebase

2020.03.20

Logging

ブラウザのプッシュ通知が簡単にできちゃうFirebaseのでやり方を簡略的に記載します。

  1. Firebaseにプロジェクトを作成する(グーグルのアカウントが必要)。
  2. firebase cliというパッケージソフトをOSにダウンロードしそのソフトを任意のフォルダの中に移動させて起動させる。Node.jsはインストール済みとする(※手順)。
  3. 試しにホスティングしてみる。ホスティングはプロジェクトの左側の項目よりホスティングをクリックすると手順の説明通り行うと出来ます。
  4. URLより確認し表示されているか確認する。
  5. Cloud Messagingの設定よりFCM でウェブ認証情報を設定するからメッセージング オブジェクトを取得するまでをブラウザで操作し設定を行う。
  6. ローカルに下記のURLよりファイルをダウンロードする。ダウンロードするファイルはfirebase-messaging-sw.js, firebase-logo.png, index.html, main.cssになります。動かない場合は再設定が必要。
    https://github.com/firebase/quickstart-js/tree/f76b14ca00cca48dbfca5c787c0a4ca73eb9857d/messaging
  7. ダウンロードしたファイルはpublicか自分が決めたフォルダに入れる。
  8. index.htmlソースの中に ‘<YOUR_PUBLIC_VAPID_KEY_HERE>’ と記載している部分があるので変更する。
  9. firebase cli より『 firebase deploy』する。
  10. ページを再読み込みして通知を許可する。
  11. Cloud Messagingから送信してみる。
  12. 通知が届くことを確認する。
    ※今回はブラウザのプッシュ通知なのでアプリを追加する際はWEB(</>)を選んでください。
Introducing Firebase Cloud Messaging

ではでは?健闘を祈る?

タグ

cli, Cloud, FCM, Firebase, firebase-logo, firebase-messaging-sw, index, JS, Messaging, node, OS, png, url, アカウント, インストール, ウェブ, オブジェクト, グーグル, クリック, ソフト, ダウンロード, パッケージ, ファイル, フォルダ, プッシュ, ブラウザ, プロジェクト, ホスティング, メッセージング, やり方, ローカル, 下記, , 任意, 作成, 取得, 左側, 必要, 情報, 手順, 操作, 確認, 移動, 簡単, 簡略, 表示, 記載, 設定, 認証, 説明, 起動, 通知, 項目,

自転車通勤を始めようかと考え中。

2015.06.29

Logging


 
自転車通勤を始めようかと考え中です。考えているだけでやらないかもしれませんが・・・・。(前の職場と違い、通勤に15分ぐらいという近い職場なので、自転車での通勤を考えてます。)全然関係ないのですが、ひそかに絵日記という項目を追加しているのですが全然、書いてません。そんな感じで自転車通勤はじめようと思いつつ。全然、動かないかもしれません。自分はそういう事が多いです。やろうと思って棚上げなことが・・・。結構、実行に移すのに時間がかかります。まずは自転車を買うというハードルが高い行動しないといけないのが、一番の難です。
実行したい気持ちはあるのです、ですがめんどくさがり屋さんなので、ついつい怠けてしまうのです。

タグ

15, nbsp, こと, ハードル, めんどくさがり, , , , 実行, 感じ, 時間, 棚上げ, 気持ち, 絵日記, 職場, 自分, 自転車, 行動, 追加, 通勤, , 項目,