Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/332.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Can';无法使用selenium从链接中获取文本_Python_Selenium - Fatal编程技术网

Python Can';无法使用selenium从链接中获取文本

Python Can';无法使用selenium从链接中获取文本,python,selenium,Python,Selenium,我无法使用selenium获取链接文本。我想从链接的文本,即842在下面的代码。我试着通过类和xpath获得。但是返回的文本是空字符串。请帮忙 Python代码: elems = wd.find_elements_by_class_name("gsc_g_al") for elem in elems: print(elem.text) elems=wd.find_element_by_xpath('/html/body/div/div[4]/div/div[2]/d

我无法使用selenium获取链接文本。我想从链接的文本,即842在下面的代码。我试着通过类和xpath获得。但是返回的文本是空字符串。请帮忙

Python代码:

elems = wd.find_elements_by_class_name("gsc_g_al")
for elem in elems:
    print(elem.text)
elems=wd.find_element_by_xpath('/html/body/div/div[4]/div/div[2]/div/div/div[3]/div/a[18]/span')
    for elem in elems:
        print(elem.text)
-一,

编辑:使用BeautifulSoup解决它。发布代码:

content = requests.get(URL)
soup = BeautifulSoup(content.text, 'html.parser') 
for tag in soup.find_all('a',{"class":"gsc_g_a"}):
    print (tag.text)

您是否尝试过
驱动程序。通过类名称(“gsc”)查找元素。文本

尝试以下操作:

linkTexts = driver.find_elements_by_xpath(".//td[@class='gsc_a_c']/a")
for e in linkTexts:
    e.text

你应该提供一些你的Python代码。你尝试了什么,什么不起作用?你能分享到网页的链接吗?返回一个空字符串。我将在问题中添加WebNote