def __init__(self): self.occupied = True if not hasattr(self, 'driver'): self.driver = webdriver.Firefox() self.driver.get('https://www.baidu.com/') self.driver.delete_all_cookies() self.driver.implicitly_wait(3)
import sys import io from bs4 import BeautifulSoup import requests import urllib.request as req import selenium import webdriver driver = webdriver.Firefox() driver.get('http://cu.bgfretail.com/product/product.do?category=product&depth2=4&sf=N') html = driver.page_source soup = BeautifulSoup(html) prodList = soup.find_all("p", {"class": "prodPrice"}) print(len(prodList)) #한글 출력할 때 문제 없게 sys.stdout = io.TextIOWrapper(sys.stdout.detach(), encoding = 'utf-8') sys.stderr = io.TextIOWrapper(sys.stderr.detach(), encoding = 'utf-8') #여러줄로 나뉜 string 을 한 줄로 def only_string(temp_text) : ret_text = '' for e in temp_text.childGenerator() : if e.string is not None : ret_text += e.string return ret_text.strip() #문장 맨 앞뒤 whitespace 제거 url = 'http://www.bokjiro.go.kr/welInfo/retrieveGvmtWelInfo.do?searchIntClId=04&searchCtgId=999&welInfSno=253&pageGb=1&domainName=&firstIndex=0&recordCountPerPage=10&cardListTypeCd=list&welSrvTypeCd=01&searchGb=01&searchWelInfNm=&pageUnit=10&key1=list&stsfCn=' req = req.urlopen(url).read() #print(req) soup = BeautifulSoup(req, 'html.parser') print(soup.prettify())
rom selenium import webdriver from selenium.webdriver.support.ui import WebDriverWait import time from selenium.webdriver.support.ui import Select try : driver = webdriver.Firefox(executable_path=r'C:\Users\Prabjot\Downloads\geckodriver.exe') driver.implicitly_wait(30) driver.maximize_window() driver.get("https://phhc.gov.in/home.php?search_param=free_text_search_judgment") WebDriverWait(driver, 10).until(lambda d: d.execute_script('return document.readyState') == 'complete') print("#############") from_date = '25/10/2020' to_date = '26/10/2020' peti_name = 'aviman' resp_name = 'kadila' search_text = 'ERPF' case_type = 'FAO' case_year = '2020' frm_date_elm = driver.find_element_by_id('from_date') frm_date_elm.clear() frm_date_elm.send_keys(from_date) to_date_elm = driver.find_element_by_id('to_date') to_date_elm.clear() to_date_elm.send_keys(to_date) driver.find_element_by_id('pet_name').send_keys(peti_name) driver.find_element_by_id('res_name').send_keys(resp_name) driver.find_element_by_id('free_text').send_keys(search_text) select_caseType_elm = Select(driver.find_element_by_id('t_case_type')) select_caseType_elm.select_by_visible_text(case_type) sel_case_yr_elm = Select(driver.find_element_by_id('t_case_year'))