Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.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 属性错误:';列表';对象没有属性';查找元素';在试图爬地铁的时候_Python_Selenium_Beautifulsoup - Fatal编程技术网

Python 属性错误:';列表';对象没有属性';查找元素';在试图爬地铁的时候

Python 属性错误:';列表';对象没有属性';查找元素';在试图爬地铁的时候,python,selenium,beautifulsoup,Python,Selenium,Beautifulsoup,我一直在努力清理subway商店,并创建一个包含地址、姓名和电话号码的表格。然而,我的代码不断给出错误填充的结果。下面是我的代码 import time import requests import csv from selenium.webdriver.common.by import By from selenium.webdriver import ActionChains from bs4 import BeautifulSoup from se

我一直在努力清理subway商店,并创建一个包含地址、姓名和电话号码的表格。然而,我的代码不断给出错误填充的结果。下面是我的代码

import time
import requests
import csv
from selenium.webdriver.common.by   import By
from selenium.webdriver             import ActionChains
from bs4        import BeautifulSoup
from selenium   import webdriver

driver = webdriver.Chrome()
driver.implicitly_wait(5)
url1 = 'http://subway.co.kr/storeSearch?page='
url2 = '&rgn1Nm=&rgn2Nm=#storeList'

addresses = []
names = []
phones = []

for i in range(41):
    driver.get(url1 + str(i) + url2)
    lst = driver.find_elements_by_xpath('/html/body/div/div[2]/div[2]/div[3]/div/div/div[1]/table/tbody/tr')
    for row in lst:
        addresses.append(lst.find_element(By.XPATH, './td[2]/div/a').text)
        names.append(lst.find_element(By.XPATH, './td[1]/a').text)
        phones.append(lst.find_element(By.XPATH, './td[4]/div').text)

stores = [{
    'address'   : props[0],
    'name'      : props[1],
    'phone'     : props[2]
} for props in zip(addresses, names, phones)]

with open('stores.csv', 'w') as csvfile:
    csvout = csv.DictWriter(csvfile, ['address', 'name', 'phone'])
    csvout.writeheader()
    csvout.writerows(stores)
那么如何访问每行中的每个元素(地址、姓名、电话)?我还添加了一个页面的图像,我正在尝试抓取一组页面


您正在调用列表对象上的
find_element
,我怀疑您想使用
,这些元素是您循环使用的元素。改变

addresses.append(lst.find_element(

对于
姓名
手机

addresses.append(row.find_element(