我正在尝试将列表拆分为单独的单元格。但是,没有逗号分隔符分隔列表,只有一个换行符。我读过一些其他的文章,它们都具有相同的属性错误,但仍然没有弄清楚我要去哪里。
我的相关代码:
from selenium import webdriver
ChromeOptions = webdriver.ChromeOptions()
driver = webdriver.Chrome('/Users/jones/Downloads/chromedriver')
driver.get('https://www.linkedin.com/in/pauljgarner/')
rows = []
name = sel.xpath('normalize-space(//li[@class="inline t-24 t-black t-normal break-words"])').extract_first()
experience = driver.find_elements_by_xpath('//section[@id = "experience-section"]/ul//li')
rows.append([name])
for item in experience:
rows[0].append(item.text)
print(item.text)
print("")
with open(parameters.file, 'w', encoding='utf8') as file:
writer = csv.writer(file)
for row in rows:
writer.writerow(row.split('\n'))
此列表来自抓取“经验”:
Freelance Python Developer
Company Name
Depop
Dates Employed
Jun 2015 – Present
Employment Duration
4 yrs 11 mos
我的代码的最后四行似乎可以解决问题,但是我收到了属性错误。我要去哪里错了?非常感谢您的帮助
[name]
将带有名称的列表追加到行,因此行中的每个项目都是其中包含一个项目的列表。试试rows.append(name)