'''
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
# 尝试传参
s = Service("chromedriver.exe")
driver = webdriver.Chrome(service=s)
driver.get('https://www.baidu.com/')
input()
'''
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
import selenium.webdriver.support.ui as ui
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
driver_path='/Users/yanghao31/Desktop/software/chromedriver.exe'
options=Options()
options.add_argument("--headless")
driver = webdriver.Chrome(options=options)
driver.get('http://www.baidu.com')
wait = WebDriverWait(driver,10,0.2)
elem = wait.until(EC.presence_of_element_located((By.CSS_SELECTOR,'.s_ipt')))
elem.send_keys('Hello world')
clickEle=wait.until(EC.presence_of_element_located((By.CSS_SELECTOR,'.s_btn_wr > input')))
clickEle.click()
driver.execute_script('window.scrollTo(0,document.body.scrollHeight)')
time.sleep(3)
driver.execute_script('window.scrollTo(0,0)')
time.sleep(3)
print(driver.page_source)
driver.quit()
import os
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
import requests
from parsel import Selector
from fake_useragent import UserAgent
def getInformation(html,cssString):
sel=Selector(text=html)
itmes=sel.css(cssString).getall()
return itmes
def getactle(html,saveDir):
cssactle='.ChapterContent_bible-reader__Du4dP'
actile=getInformation(html,cssactle)[0]
cssTitle='.ChapterContent_reader__UZc2K h1::text'
title=getInformation(actile,cssTitle)[0]
text=''
Cssrow='.ChapterContent_p___9Q1l, .ChapterContent_heading__RjEme'
rows=getInformation(actile,Cssrow)
for row in rows:
cssText='.ChapterContent_content__dkdqo *::text'
texts=getInformation(row,cssText)
if len(texts)==0:
cssText = '.ChapterContent_heading__RjEme *::text'
texts = getInformation(row, cssText)
textFinal=''.join(texts)
text+=textFinal+'\n'
savePath=os.path.join(saveDir,title+'.txt')
with open(savePath,'w',encoding='utf-8') as file:
file.write(title)
file.write(text)
return title,text
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
def GetHtml_run(url):
options = webdriver.ChromeOptions()
options.add_experimental_option("detach", True)
options.add_argument(f'user-agent={UserAgent().random}')
service = Service(executable_path='/Users/yanghao31/Desktop/software/chromedriver_mac_arm64/chromedriver')
driver = webdriver.Chrome(service=service)
print('准备完毕')
driver.set_page_load_timeout(30)
try:
driver.get(url)
driver.implicitly_wait(30)
html = driver.page_source
except TimeoutException:
print("页面加载超时")
html = ''
driver.quit()
return html
from selenium.webdriver.chrome.options import Options
def GetHtml_TitleAndDes(url):
options = Options()
options.add_argument('--headless')
options.add_argument(f'user-agent={UserAgent().random}')
options.add_argument('--disable-gpu')
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
driver = webdriver.Chrome(options=options)
print('准备完毕')
driver.set_page_load_timeout(30)
try:
driver.get(url)
driver.implicitly_wait(30)
title = driver.title
description = driver.find_element(by=By.CSS_SELECTOR,value='meta[name="description"]').get_attribute('content')
except TimeoutException:
print("页面加载超时")
html = ''
title, description='',''
html=driver.page_source
cssdes='meta[name="description"]::attr(content)'
des1=getInformation(html,cssdes)
csstitle='title *::text'
title1=getInformation(html,csstitle)
print({"Title":title1,"Des":des1})
driver.quit()
return title,description
def main():
textPath='/Users/yanghao31/Desktop/test/SeleniumTest/text'
audioPath='/Users/yanghao31/Desktop/test/SeleniumTest/audio'
if not os.path.exists(textPath):
os.makedirs(textPath)
if not os.path.exists(audioPath):
os.makedirs(audioPath)
options = webdriver.ChromeOptions()
options.add_experimental_option("detach", True)
options.add_argument(f'user-agent={UserAgent().random}')
service = Service(executable_path='/Users/yanghao31/Desktop/software/chromedriver_mac_arm64/chromedriver')
driver = webdriver.Chrome(service=service)
print('准备完毕')
driver.get('https://www.flaru.com/en/soundgasm.net/M4F-audio-nsfw')
html = driver.page_source
print(html)
a=input()
def GetInformation(html,cssString):
sel= Selector(text=html)
items=sel.css(cssString).getall()
return items
if "__main__" == __name__:
url='https://www.pinterest.jp/search/pins/?q=natural%20japanese%20makeup&rs=typed'
html=GetHtml_run(url)
print(html)
hrefs='a.Wk9.CCY.S9z.ho-.kVc.xQ4::attr(href)'
href=GetInformation(html,hrefs)
print(href)