selenium驱动chrome

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/a1368783069/article/details/80866000

直接上代码,之后解释

#coding:utf-8
import time
from bs4 import BeautifulSoup
from selenium import webdriver
path = "/Users/yh/workshop/xplace/temp/chromedriver"
chrome_options = webdriver.chrome.options.Options()
chrome_options.set_headless(headless=True)
driver=webdriver.chrome.webdriver.WebDriver(executable_path=path,options=chrome_options)

driver.maximize_window()
# driver.implicitly_wait(10)
driver.get('https://en.wikipedia.org/wiki/Unexpected_hanging_paradox')
time.sleep(2)
out = driver.execute_script("return document.getElementsByTagName('html')[0].innerHTML;")
# out = driver.execute_script("return document.title")
print("out....",out)
# body = driver.find_element_by_tag_name('body')
# print(body.text)
# driver.implicitly_wait(400)

# html = driver.page_source
# soup = BeautifulSoup(html, "lxml")
# for tag in soup.find_all():
#     if tag.name in ["script"]:
#         tag.decompose()
#     else:
#         print(tag.name)

driver.quit()

猜你喜欢

转载自blog.csdn.net/a1368783069/article/details/80866000
今日推荐