Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Selenium与webdriver错误&;在非类型情况下打印null_Python_Pandas_Selenium_Google Chrome_Selenium Chromedriver - Fatal编程技术网

Python Selenium与webdriver错误&;在非类型情况下打印null

Python Selenium与webdriver错误&;在非类型情况下打印null,python,pandas,selenium,google-chrome,selenium-chromedriver,Python,Pandas,Selenium,Google Chrome,Selenium Chromedriver,我想在一个银行网站上浏览,但谷歌chrome驱动程序不起作用。 如果类型为“NoneType”,我想打印为“null” 我在jupyter笔记本(anaconda3)中编写了这段代码 我试图用“如果……否则……”来解决这个问题 from bs4 import BeautifulSoup from urllib.request import urlopen from selenium import webdriver driver = webdriver.Chrome('./chromed

我想在一个银行网站上浏览,但谷歌chrome驱动程序不起作用。 如果类型为“NoneType”,我想打印为“null” 我在jupyter笔记本(anaconda3)中编写了这段代码

我试图用“如果……否则……”来解决这个问题

from bs4 import BeautifulSoup

from urllib.request import urlopen

from selenium import webdriver 

driver = webdriver.Chrome('./chromedriver.exe') html_dr = driver.execute_script('return document.body.innerHTML') #question

url_base = 'https://www.kebhana.com/cont/mall/mall08/mall0805/index.jsp?_menuNo=62608'

html = urlopen(url_base) soup = BeautifulSoup(html, "html.parser")

soup

print(soup.find_all('li', 'item type1'))

len(soup.find_all('li', 'item type1'))

from urllib.request import urljoin

name = [] url_add = [] period = [] strong = [] term = []

list_soup = soup.find_all('li', 'item type1')

for item in list_soup: name.append(item.find('a').get_text()) url_add.append(urljoin(url_base, item.find('a')['href'])) #question # # #'NoneType' object has no attribute 'get_text' #if item is not None: #period.append(item.find(class_='period').get_text()) #strong.append(item.find('strong')) #term.append(item.find(class_='term')) #else: #print("null")

url_add[:5]

name[:5]

period[:23]

strong[:23]

import pandas as pd

data = {'Name':name, 'URL':url_add} df = pd.DataFrame(data) df.head() df.to_csv('./hana_list.csv', sep=',', encoding='EUC-KR')

df['URL'][0]

html = urlopen(df['URL'][0]) soup_tmp = BeautifulSoup(html, "html.parser") soup_tmp

print(soup_tmp.find('dl', 'prodcutInfo'))

print(soup_tmp.find('div', 'exist_table'))

print(soup_tmp.find(class_='tbl_tbldiv'))

“NoneType”对象没有属性“get\u text”

您要调用两次“get\u text”。您已对其中一个进行了错误检查,但未对另一个进行检查

for item in list_soup: 
    name.append(item.find('a').get_text())    #<--- you may also need to check item for not None here
    url_add.append(urljoin(url_base, item.find('a')['href'])) 
    if item is not None: 
        period.append(item.find(class_='period').get_text())   #<--- you are checking item for not None here
        strong.append(item.find('strong')) 
        term.append(item.find(class_='term')) 
    else: 
        print("null")
列表中项目的

name.append(item.find('a').get_text())#请正确缩进代码。此外,请解释“不起作用”的含义。是否有错误消息?如果是,则包括堆栈跟踪。