我想从以下 HTML 中提取“xms”
<div class="ki-kullaniciadi member-info" member-info-memberid="12789" member-info-forumid="2613">
<a href="/profil/12789">
<b>xms</b>
</a>
</div>
我已经尝试过了
def scrapecomments2(url):
tic = time.perf_counter()
wait = WebDriverWait(wd,20)
wd.get(url)
data2=[]
for comment in wait.until(EC.presence_of_all_elements_located((By.CSS_SELECTOR, "div.ki-kullaniciadi.member-info b"))):
data2.append(comment.text)
toc = time.perf_counter()
print(data2)
return data2
包括许多组合,例如
for comment in wait.until(EC.presence_of_all_elements_located((By.CLASS_NAME, "ki-kullaniciadi b"))):
data2.append(comment.text)
for comment in wait.until(EC.presence_of_all_elements_located((By.XPATH,"//div[@class='ki-kullaniciadi']/a/b"))):
data2.append(comment.text)
它总是回来
TimeoutException Traceback (most recent call last)
<ipython-input-8-e105fdffd5ff> in <cell line: 1>()
----> 1 scrapev2=scrapecomments2('https://forum.donanimhaber.com/tesla-model-y-kullananlar-kulubu-2023--155488676-1151')
1 frames
/usr/local/lib/python3.10/dist-packages/selenium/webdriver/support/wait.py in until(self, method, message)
103 if time.monotonic() > end_time:
104 break
--> 105 raise TimeoutException(message, screen, stacktrace)
106
107 def until_not(self, method: Callable[[D], T], message: str = "") -> Union[T, Literal[True]]:
TimeoutException: Message:
但是
for comment in wait.until(EC.presence_of_all_elements_located((By.TAG_NAME,"b"))):
data2.append(comment.text)
有效,因此看起来页面加载不存在问题。它返回页面中带有标签 b 的每个值,但我只想要“ki-kullaniciadi member-info”类上的值。
for comment in wait.until(EC.presence_of_all_elements_located((By.CSS_SELECTOR, ".ki-kullaniciadi .member-info a b")))