Python+Selenium=href中没有结果



所以我没有太多关于硒的exp等等,我试着使用youtube+一些论坛帖子来创建一个抓取代码,因为我是一名摄影师,我和该领域的其他人一起工作,如果能得到所有摄影师的列表,那就太棒了,让我展示代码,所以基本上现在,我只想在这里获得摄影师的名字(稍后我需要了解硒的分页,但首先我必须通过这个问题(:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
import sys

PATH = "C:Program Files (x86)chromedriver.exe"
driver = webdriver.Chrome(PATH)
bloom ="https://www.photographer.org/?geodir_search=1&stype=gd_place&sgd_placecategory%5B0%5D=8&s=+&snear&sgeo_lat&sgeo_lon"
driver.get(bloom)
eList = driver.find_elements_by_class_name('geodir-entry-title')

hrefList = []
for a in eList:
hrefList.append(a.get_attribute('href'))
for href in hrefList:
print(href)

结果是无、无、无等。。。应该是";Tsukimi Photography"Cherry Logan摄影;等等。

有什么建议可以帮我吗?

感谢

查看html,我可以看到类为geodir-entry-title的元素没有href属性。因此,None上的输出是意料之中的。href的期望值类似于";https://www.photographer.org/photographers/tsukimi-photography/">

<h3 class="geodir-entry-title">
<a href="https://www.photographer.org/photographers/tsukimi-photography/" title="Tsukimi Photography">
Tsukimi Photography
</a>
</h3>

这可以按照如下方式进行。

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.keys import Keys
import time
import sys
PATH = "C:Program Files (x86)chromedriver.exe"
driver = webdriver.Chrome(PATH)
bloom ="https://www.photographer.org/?geodir_search=1&stype=gd_place&sgd_placecategory%5B0%5D=8&s=+&snear&sgeo_lat&sgeo_lon"
driver.get(bloom)
eList = WebDriverWait(driver, 5).until(EC.visibility_of_all_elements_located(
(By.XPATH, "//h3[@class='geodir-entry-title']//a")))

hrefList = []
for a in eList:
hrefList.append(a.get_attribute('href'))
for href in hrefList:
print(href)

相关内容

  • 没有找到相关文章

最新更新