Webスクレイピング​ inputに文字を​入力する形で検索を行​いたい

31 views (last 30 days)
Huge Grave
Huge Grave on 18 Jun 2022
Answered: Hernia Baby on 19 Jun 2022
この質問をご覧いただきありがとうございます。
Matlabを用いてWebスクレイピングを行いたく、その一つとして検索フォームに文字を入力したいと考えています。
前回の質問ではURL+検索ワードという形で解決案を出していただきましたが、私の手法とはかみ合いませんでした。
今回は例としてMatlabAnswerに検索ワードを入力し質問を検索するプログラムを作りたいと考えました。
URL = 'https://jp.mathworks.com/matlabcentral/answers';
response = webwrite(URL,'term','検索ワード');
上記で行いましたがうまく行かなかったため、改善点をご教授願いたいと考えております。

Accepted Answer

Hernia Baby
Hernia Baby on 19 Jun 2022
おそらくseleniumのようなものを探しているのかなと思います。
探す限り見つからないので、Pythonとの連携で行いました。
Anacondaとchromedriverをダウンロードし、必要なモジュールをインストールします。
(Anacondaでなくても問題ありません)。
urlと検索文字を設定します。
clc,clear;
url = 'https://www.google.com/';
word = input('検索ワードを入れてください: ','s');
MATLAB Live Task for Python というタスクがアドインで入れられるので、以下はそこで編集しました。
pythonCode = [
"import time"
"from selenium import webdriver"
"driver = webdriver.Chrome(options=ChromeOptions)"
"driver.implicitly_wait(3)"
"driver.get(url)"
"search = driver.find_element_by_name('q')"
"search.send_keys(word)"
"search.submit()"
"time.sleep(5)"
];
pyrun(pythonCode, "url", url, "word", word);

More Answers (0)

Products


Release

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!