-
【JavaScript】AJAX(非同期通信)の使い方
JavaScript
JavaScriptでAJAX(非同期通信)の使うには、JavaScript APIの1つであるXHR (XMLHttpRequest)を利用します。 function reqListener() { console.log(this.responseText); } const req = new XMLHttpRequest(); // オブジェクトの作成 req.addEventListener... -
【JavaScript】即時関数(IIFE)の書き方
JavaScript
即時関数(IIFE→Immediately Invoked Function Expression) (function () { // … })(); (() => { // … })(); (async () => { // … })(); 参考:https://developer.mozilla.org/en-US/docs/Glossary/IIFE 補足:自己実行無名関数 参考:https://developer.... -
Seleniumで開いたページのHTMLを取得・保存する
Selenium
単一ページ from selenium import webdriver import time url = "https://example.com/" driver = webdriver.Chrome() driver.get(url) time.sleep(10) html = driver.page_source with open("filename.html", 'w') as file: file.write(html) 複数ページ ... -
Python type XXX cannot be converted
Python
mysql.connector.errors.InterfaceError: Failed executing the operation; Python type Tag cannot be converted BeautifulSoupを使用して取得したHTMLタグをそのままMySQLにデータ挿入しようとした時に表示されたエラー。 soup.find(class_="xxx") # Tag... -
【Python】ライブラリ「Pandas」の使い方
PHP
Pandasのインストール pip install pandas Pandasの使い方 import pandas list = [] list.append(xxx) dataFrame = pandas.DataFrame({'data': list}) dataFrame.to_csv('file_name.csv', index=False) -
Seleniumでプルダウンの要素を選択する
PHP
from selenium.webdriver.support.ui import Select dropdown = Select(driver.find_element(by='id')) dropdown.deselect_by_index() dropdown.deselect_by_value() dropdown.deselect_by_visible_text() -
Seleniumで取得した要素のHTMLを取得する
Selenium
element = driver.find_element(by="xxx", value="xxx") html = element.get_Attribute('innerHTML') html = element.get_Attribute('outerHTML') -
Seleniumで開いたページのHTMLを取得する
Selenium
from selenium import webdriver target = 'https://www.yahoo.co.jp/' driver = webdriver.Chrome() driver.get(target) print(driver.page_source) driver.quit() -
【Selenium】遅延読み込み
Selenium
import time time.sleep(3) xxx -
Seleniumでボタンをクリックする
Selenium
btn = driver.find_element(by='xpath', value='//tag[@attr="xxx"]') btn.click()