简体   繁体   English

如何使用 selenium 从“a”标签获取 href 文本

[英]How to get href text from 'a' tag with selenium

I am trying to scrape a page.. But the link I need is in an href in an 'a' tag.我正在尝试抓取一个页面。但我需要的链接位于“a”标签中的 href 中。 how can I get it with selenium (or BS4)我怎样才能用 selenium(或 BS4)得到它

my code..我的代码..

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import pandas as pd
from bs4 import BeautifulSoup
import requests
import pyautogui as ptg 

PATH = "C:\Program Files (x86)\chromedriver.exe"
SRC = requests.get("Link (hidden for security)").text
SOUP = BeautifulSoup(SRC, 'lxml')

driver = webdriver.Chrome(PATH)
driver.get("Link (hidden for security)")
#driver.execute_script("window.scrollBy(0,1500)")

email = "(Hidden for security)"
password = "(Hidden for security)"

log_in_btn_1 = driver.find_element_by_xpath("/html/body/div/div/div[2]/div/div[1]/div[2]/a[2]").click()
#email_input_btn = driver.find_element_by_xpath("/html/body/div/div/div[2]/div/table/tbody/tr/td/div[3]/div[2]/form/ul/li[1]/input").click()


#Point(x=325, y=234) // email coords
#Point(x=588, y=303) // pass coords
ptg.click(325, 234)
ptg.typewrite(email, interval=0.05)
ptg.click(588, 303)
ptg.typewrite(password, interval=0.05)

log_in_btn_2 = driver.find_element_by_xpath("/html/body/div/div/div[2]/div/table/tbody/tr/td/div[3]/div[2]/form/ul/li[3]/input").click()

#Point(x=1188, y=59) // URL area

post_link = "(hidden for security)"

ptg.click(537, 75)
ptg.typewrite(post_link)
ptg.typewrite(["enter"])

The links are hidden for security purposes出于安全目的,链接被隐藏


please help.请帮忙。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM