Python Selenium chrome和safari WebDriver“;通过xpath查找元素;论网络元素
我一直在努力使我的代码在chrome(Windows7)上运行,而且它在运行OSx的safari上确实起到了作用 以下是OSx的代码:Python Selenium chrome和safari WebDriver“;通过xpath查找元素;论网络元素,python,macos,google-chrome,selenium,safari,Python,Macos,Google Chrome,Selenium,Safari,我一直在努力使我的代码在chrome(Windows7)上运行,而且它在运行OSx的safari上确实起到了作用 以下是OSx的代码: import time from selenium import webdriver from selenium.webdriver.common.action_chains import ActionChains import re from bs4 import BeautifulSoup import pa
import time
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
import re
from bs4 import BeautifulSoup
import pandas as pd
import csv
driver = webdriver.Safari()
driver.get('https://xxxxxxxxxxxx.com')
opp = driver.find_elements_by_xpath("//a[contains(@class, 'com_TI-B')]/@onclick")
to_be_visited = []
p = re.compile('contentForm\:j_idt\d+\:j_id\d+\:j_id\d+')
for x in opp:
doc_ids = (p.findall(x.text)[0])
to_be_visited.append(doc_ids)
以下是Chrome的代码:
import time
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
import re
from bs4 import BeautifulSoup
import pandas as pd
import csv
driver = webdriver.Chrome()
driver.get('https://xxxxxxxxxxxxxxxxxxxxxxxx.com')
opp = driver.find_elements_by_xpath('//a[contains(@class,"com_TI-B")]/@onclick')
to_be_visited = []
p = re.compile('contentForm\:j_idt\d+\:j_id\d+\:j_id\d+')
print(p)
for x in opp:
doc_ids = (p.findall(x.text)[0])
to_be_visited.append(doc_ids)
这是我第一次使用selenium,我经常会遇到如下错误
xpath表达式“//a[的结果包含(@class,“com_TI-B”)
)]/@onclick“是:[object Attr]。它应该是一个元素
我想知道chrome和safari的webdriver之间是否有区别