我正在努力浏览以下网站:
finsight.com/product/us/abs/ee.
特别是,对于每一行,我都试图提取类型(AUTO或CBMS)、公司名称,并下载链接。下面是每行1的源代码摘录。然而,当我运行循环时,我只得到第一行的名称和链接(在本例中是AUTo CarMax AUTo Owner Trust 2018-2)。你知道吗
到目前为止,我有以下代码:
import selenium
import time
import requests
from selenium import webdriver
url = "https://finsight.com/product/us/abs/ee"
driver = webdriver.Chrome()
driver.get(url)
time.sleep(1)
company_row = driver.find_elements_by_xpath("//div[@class='ee-item portlet box ng-scope']")
for row in company_row:
RD_element = row.find_element_by_xpath("//a[@class='related-document ng-scope']")
company_name = row.find_element_by_xpath("//span[contains(@class,'filing-left filing-issuer ng-binding')]")
company_type = row.find_element_by_xpath("//span[contains(@class,'filing-left filing-sector ng-binding')]")
RD_link = RD_element.get_attribute('href')
print (company_name.text)
print (company_type.text)
print (RD_link)
我的代码输出如下:
DevTools listening on ws://127.0.0.1:12060/devtools/browser/c5d13168-0976-41c7-937c-ff2bd4cd99fe
CarMax Auto Owner Trust 2018-2
AUTO
https://finsight.com/api/download-csv?file_id=15395
CarMax Auto Owner Trust 2018-2
AUTO
https://finsight.com/api/download-csv?file_id=15395
CarMax Auto Owner Trust 2018-2
AUTO
https://finsight.com/api/download-csv?file_id=15395
CarMax Auto Owner Trust 2018-2
AUTO
https://finsight.com/api/download-csv?file_id=15395
CarMax Auto Owner Trust 2018-2
以下是您案例的工作代码:
输出:
PS:这里我使用CSS选择器而不是XPath。你知道吗
相关问题 更多 >
编程相关推荐