我正在尝试抓取该网站https://opencollective.com/discover 获取所有项目名称并将这些名称存储在csv文件中。
from selenium import webdriver
chromedriver = "/home/myname/Documents/chromedriver"
driver = webdriver.Chrome(chromedriver)
driver.get("https://opencollective.com/discover")
name = driver.find_elements_by_xpath('//div[@class = "CollectiveCard-name"]')
titles = [x.text for x in name]
with open('discover_file.csv', mode='w') as discover_file:
discover_writer = csv.writer(discover_file, delimiter = ',')
discover_writer.writerow(titles)
但是,当我在此代码上运行PDB时,我可以根据需要获取名称。如下。
/home/myname/Documents/GitHub_Project/test.py(16)() -> chromedriver =“ / home / myname / Documents / chromedriver” (Pdb)n /home/myname/Documents/GitHub_Project/test.py(19)() ->驱动程序= webdriver.Chrome(chromedriver) (Pdb)n /home/myname/Documents/GitHub_Project/test.py(22)() -> driver.get(“ https://opencollective.com/discover”) (Pdb)n /home/myname/Documents/GitHub_Project/test.py(25)() ->名称= driver.find_elements_by_xpath('// div [@class =“ CollectiveCard-name”]') (Pdb)n /home/myname/Documents/GitHub_Project/test.py(27)() ->标题= [名称中x的x.text] (Pdb)名称[0]。文本 你'webpack' (Pdb)名称[1]。文本 u'Babel'
有人可以解释一下为什么会发生这种情况以及需要做什么吗? 预先感谢。