【发布时间】:2021-08-23 05:43:54
【问题描述】:
亲爱的, 我正在尝试获取谷歌搜索结果的链接,我正在使用这个 profiles = driver.find_elements_by_xpath('//*[@class="r"]/a[1]') 这工作正常,我现在正在使用它,但没有给我结果
import csv
from parsel import Selector
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
import itertools
import random
listlong = []
driver = webdriver.Chrome('C:/chromedriver.exe')
driver.get('https://www.google.com/search?q=&num=200&start=0&sourceid=chrome')
time.sleep(random.randint(10,11))
search_input = driver.find_element_by_name('q')
search_input.send_keys('site:linkedin.com/in/ AND USA')
time.sleep(3)
search_input.send_keys(Keys.RETURN)
time.sleep(3)
# grab all linkedin profiles from first page at Google
profiles = driver.find_elements_by_xpath('//*[@class="r"]/a[1]')
time.sleep(8)
profiles = [profile.get_attribute('href') for profile in profiles]
listprof = profiles.copy()
listlong.extend(listprof)
print(profiles)
print("f1")
print(listprof)
print("f2")
print(listlong)
print("f3")
driver.quit()
什么是 xpath 可以用来代替这个 driver.find_elements_by_xpath('//*[@class="r"]/a[1]')
【问题讨论】:
-
你能添加一张你想要得到的截图吗?
标签: python selenium selenium-webdriver