自动化元素点击中的正则表达问题
import requestsfrom lxml import etree
import csv
from selenium import webdriver
from selenium.webdriver.common.by import By
import time
from selenium.webdriver.support.ui import WebDriverWait
import requests
import base64
import selenium.webdriver.support.expected_conditions as EC
import datetime
import urllib.request
import re
import os
import PyPDF2
from PyPDF2 import PdfFileReader
from bs4 import BeautifulSoup
import io
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options
s = requests.Session()
fb = webdriver.FirefoxProfile.DEFAULT_PREFERENCES
# op = webdriver.FirefoxOptions()
# op.set_preference({'user-data-dir':''})
c = webdriver.ChromeOptions()
c.add_argument('--user-data-dir=D:/AutomationProfile')
c.add_argument('--headless')
# c.add_argument(f'user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36')
driver = webdriver.Chrome()
driver.get('https://www.jiaoyifamen.com/variety/research-report')
time.sleep(5)
driver.find_element(By.XPATH, '//div').click()
time.sleep(3)
我想要实现:点击含有“玉米”的链接。能够使用正则表达的方式实现吗?(设想中的是:driver.find_element(By.XPATH, '//div').click())
driver.find_element(By.XPATH, '//div').click()
xpath并不直接支持re 本帖最后由 isdkz 于 2023-1-10 16:41 编辑
xpath不能使用正则表达式,但是有一个模糊定位,你直接搜 xpath 模糊定位
xpath模糊定位
页:
[1]