def __init__(self, username, pw, pname): self.driver = webdriver.Chrome() self.username = username self.driver.get("https://github.com/login") sleep(2) self.driver.find_element_by_id("login_field")\ .send_keys(username) sleep(2) self.driver.find_element_by_id("password")\ .send_keys(pw) self.driver.find_element_by_xpath("/html/body/div[3]/main/div/form/div[4]/input[9]")\ .click() sleep(2) self.driver.find_element_by_xpath("/html/body/div[4]/div/aside[1]/div[2]/div[2]/div/h2/a")\ .click() sleep(2) self.driver.find_element_by_xpath("/html/body/div[4]/main/div/form/div[2]/auto-check/dl/dd/input")\ .send_keys(pname) sleep(2) self.driver.find_element_by_xpath("/html/body/div[4]/main/div/form/div[3]/button")\ .click() sleep(2) self.driver.find_element_by_class_name("Header-link")\ .click() sleep(2) self.driver.find_element_by_class_name("dropdown-item dropdown-signout")\ .click() sleep(10)
def login(self): self.driver = webdriver.Chrome() self.driver.get(self.url) time.sleep(5) try: self.driver.find_element_by_id("lgPwd").clear() #self.driver.find_element_by_id("loginpassword").clear() #判断是否需要登录密码 except Exception as a: pass else: self.driver.find_element_by_id("lgPwd").send_keys("12345678") #如果需要密码输入12345678 self.driver.find_element_by_id("loginSub").click() time.sleep(3)
def estabilish_driver(self): """ Creates chromedriver instance with arguments. If used inside Docker, specify env variable: SCRAPPER_ENV=DOCKER to inject additional arguments to driver for stability. """ chrome_options = webdriver.ChromeOptions() chrome_options.add_argument(f'--log-path={LOG_PATH}/chromedriver.log') if os.environ.get('SCRAPPER_ENV', '') == 'DOCKER': for arg in DOCKER_ARGS: chrome_options.add_argument(f'--{arg}') return webdriver.Chrome(chrome_options=chrome_options)
def purchaseproduct(url): driver = webdriver.Chrome(executable_path=r'\usr\local\bin\chromedriver') driver.get(str(url)) driver.find_element_by_xpath('//div[@data-value="L"]').click() time.sleep(2) driver.find_element_by_xpath('//button[@id="AddToCart"]').click() time.sleep(2) driver.find_element_by_xpath('//button[@value="Check Out"]').click() time.sleep(4) driver.find_element_by_xpath('//input[@placeholder="Email"]').send_keys("*****@*****.**") time.sleep(1) driver.find_element_by_xpath('//input[@placeholder="First name"]').send_keys("Junyoung") time.sleep(1) driver.find element by xpath('//input[@placeholder="Last name"]').send_keys("Bae") time.sleep(1) driver.find element by xpath('//input[@placeholder="Address"]').send_keys("Surisan-ro 40") time.sleep(2) driver.find element by xpath('//input[@placeholder="City"]').send_keys("Gunpo-Si") time.sleep(1) driver.find element by xpath('//input[@placeholder="Zip code"]').send_keys("15823") time.sleep(1) driver.find element by xpath('//input[@placeholder="phone"').send_keys("01074771111")
import selenium import webdriver import pandas as pd import time # settings options = webdriver.ChromeOptions() options.add_argument('--headeless') options.add_argument('--disable-gpu') options.add_argument('--lang=ja') browser = webdriver.Chrome(chrome_options=options, excecutable_path='./chromedriver') df = pd.DataFrame(columns=['name', 'address', 'location0', 'location1', 'location2'])
from selenium.webdriver.chrome.options import Options from bs4 import BeautifulSoup import csv url='https://www.sofascore.com/tournament/football/england/premier-league/17' ##We did it years=['01/02','02/03','03/04','04/05','05/06','06/07','07/08','08/09','09/10','10/11','11/12','12/13','13/14','14/15','15/16','16/17','17/18'] hrefs=[] for year in years: chrome_options = Options() chrome_options.add_argument("--start-maximized") driver = webdriver.Chrome(executable_path="C:/Users/Matteo/Downloads/chromedriver",chrome_options=chrome_options) driver.get(url) driver.find_element_by_class_name("dropdown__toggle--compact").click() driver.find_element_by_link_text(year).click() soup = BeautifulSoup(driver.page_source, "lxml") control=True while control: try: fo=soup.find('div','js-event-list-tournament tournament') for link in fo.find_all('a'): hrefs.append(link.get('href')) driver.find_element_by_class_name('js-tournament-page-show-previous-week').click()
import selenium import webdriver import pandas as pd import time # settings options = webdriver.ChromeOptions() options.add_argument('--headeless') options.add_argument('--disable-gpu') options.add_argument('--lang=ja') browser = webdriver.Chrome(chrome_options=options)
from selenium.webdriver.common.action_chains import ActionChains from selenium.webdriver.support.ui import Select import numpy as np import json with open('data.json') as json_file: data = json.load(json_file) def id_converter(id): real_id= id[0:start_pos]+ unique_key +id[id.find('0a'):] return real_id usernameStr = '*****@*****.**' passwordStr = 'Harry20010102' browser = webdriver.Chrome() browser.get('https://online.immi.gov.au/lusc/login') # fill in username and hit the next button username = browser.find_element_by_id('username') username.send_keys(usernameStr) password = browser.find_element_by_id('password') password.send_keys(passwordStr) loginButton = browser.find_element_by_name('login') loginButton.click() continueButton = browser.find_element_by_name('continue') continueButton.click() newappButton = browser.find_element_by_id('btn_newapp') newappButton.click()
def start_chrome_driver(): import webdriver chrome_path = "/Users/pAulse/Documents/Projects/webpage-copier/chromedriver" driver = webdriver.Chrome(executable_path=chrome_path) # driver.set_window_size(window_width, window_height) return driver
import webdriver from selenium driver=webdriver.Chrome()
import requests from bs4 import BeautifulSoupfrom selenium import webdriver from bs4 import BeautifulSoup import re import time import csv import io import pprint as pp import pandas as pd path_to_chromedriver ="C:\\Users\\MANN PATEL\\Downloads\\chromedriver_win32\\chromedriver" #enter path of chromedriver browser = webdriver.Chrome(executable_path = path_to_chromedriver) url = input("Enter the url: ") #eg: https://www.twitter.com/xyz/ #this function is to handle dynamic page content loading - using Selenium def tweet_scroller(url): browser.get(url) #define initial page height for 'while' loop lastHeight = browser.execute_script("return document.body.scrollHeight") while True: browser.execute_script("window.scrollTo(0, document.body.scrollHeight);") #define how many seconds to wait while dynamic page content loads time.sleep(3) newHeight = browser.execute_script("return document.body.scrollHeight")
##################################################################### #### Setup # set download folder downloadFilePath = "/Users/cindycheng/Dropbox/Documents/SNIS/Data/Codex" # driver options chrome_options = webdriver.ChromeOptions() prefs = {"download.default_directory": downloadFilePath, "download.prompt_for_download":False, "plugins.plugins_disabled": ["Chrome PDF Viewer"]} chrome_options.add_experimental_option("prefs", prefs) # initiate webdriver driver = webdriver.Chrome(executable_path = "/Users/cindycheng/Dropbox/Documents/SNIS/Data/chromedriver" , chrome_options=chrome_options) # Collect all the years that you are going to scrape page_to_scrape = "http://www.codexalimentarius.org/meetings-reports/en/" webpage = urllib2.urlopen(page_to_scrape) soup = BeautifulSoup(webpage.read()) YEARS = soup.findAll("a", { 'class': 'external-link-new-window yearsLinks' }) nLinks = len(YEARS) ##################################################################### ##################################################################### for year in xrange(0, len(YEARS)):
# API 트래픽 초과시 이용할 임시 코드 rom selenium import webdriver from selenium.webdriver.common.keys import Keys from bs4 import BeautifulSoup from urllib.request import urlopen url = "https://papago.naver.com" driver = webdriver.Chrome("C:\chromedriver.exe") driver.get(url) html = urlopen(url).read() soupData = BeautifulSoup(html, 'html.parser') elem = driver.find_element_by_xpath('//*[@id="txtSource"]') elem.send_keys("testing") elem2 = driver.find_element_by_xpath('//*[@id="btnTranslate"]') elem2.click() ''' 여기까지는 제대로 동작. 그러나 번역하기 버튼 누른 다음에 나오는 결과 텍스트가 파싱이 잘 안됨 ''' tList = soupData.select("##txtTarget > span") print(tList) driver.close()
def __init__(self): self.driver = webdriver.Chrome() # or Firefox() or smth else self.navigate()
def __init__(self): self.driver=webdriver.Chrome()