0
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

スクレイピング関係まとめ(selenium,pyautogui)

Last updated at Posted at 2020-05-12

・pip install pyautoguiとseleniumをやる

#selenium


#ライブラリをインポート
from selenium import webdriver
from selenium.webdriver.support.ui import Select
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options
import os
import time
import requests
from selenium.webdriver.common.keys import Keys
import requests
from bs4 import BeautifulSoup
import pyautogui
import pandas as pd
from selenium.webdriver.common.action_chains import ActionChains
from selenium.common.exceptions import NoSuchElementException
import datetime as dt
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions

def LOG_IN():    
    #クロームドライバーを指定
    driver = webdriver.Chrome(**chromedriver.exe**)

    driver.get("hoghoge")

    #ユーザーID、パスワード、ログインボタンのタグを取得
    userId = driver.find_element_by_name('userId')
    password = driver.find_element_by_name('password')
    loginButton = driver.find_element_by_name('login')
    
    #ユーザーIDとパスワードを入力してログイン
    userId.send_keys('hogehoge')
    password.send_keys('hogehoge')
    loginButton.submit()
    
    return driver

・色々な指定方法

#エレメントの指定
driver.find_element_by_name()
driver.find_element_by_xpath()
driver.find_element_by_id()

#操作方法
.click()
.clear()
.send_keys()
.text

#pyautogui


import os
import pandas as pd
import pyautogui
import pyperclip
from time import sleep
import win32com.client
import win32gui
import time
import openpyxl
from tkinter import *
import glob

#今のマウスの場所を調べる
print(pyautogui.position())
pyautogui.moveTo(35,170, duration=0.1)#移動
pyautogui.click()#クリック
pyautogui.dragTo(1350,670, duration=0.3, button='left')#ドラッグ
pyautogui.typewrite(txt)#テキスト入力

#クリップボードのコピー
df = pd.read_clipboard()

#ハンドラの取得
hWnd = win32gui.FindWindow(0, "アプリ名")
if hWnd is not 0:
    win32gui.SetForegroundWindow(hWnd)
0
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?