Python 3.x BeautifulSoup返回None
为什么Python 3.x BeautifulSoup返回None,python-3.x,selenium,beautifulsoup,Python 3.x,Selenium,Beautifulsoup,为什么页面返回为无? 这里是错误 from selenium import webdriver from bs4 import BeautifulSoup import time ################import the chrome web driver and define the location############### driver = webdriver.Chrome(executable_path='C:/Users/../Downloads/cd79/chrome
页面
返回为无
?
这里是错误
from selenium import webdriver
from bs4 import BeautifulSoup
import time
################import the chrome web driver and define the location###############
driver = webdriver.Chrome(executable_path='C:/Users/../Downloads/cd79/chromedriver.exe')
###################################################################################
###########open the web page and print the title##############
page = driver.get("https://kjustin765.wixsite.com/website")
print(driver.title)
driver.maximize_window()
time.sleep(5)
while True:
soup = BeautifulSoup(page.content, 'html.parser')
button1 = soup.find('span', class_='pWNha').text
if 'Yes' in button1:
driver.refresh()
else:
button1.click()
要获取正确的数据,请使用
page.page\u source
而不是page.content
:
soup = BeautifulSoup(page.content, 'html.parser')
AttributeError: 'NoneType' object has no attribute 'content
如果您使用
.content
方法请求页面,则该方法来自请求
库。例如:
soup = BeautifulSoup(page.page_source, 'html.parser')
美化组(driver.page_源代码'html.parser')
import requests
page = requests.get(my_url).content