第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

谷歌地圖一些 XPATH 選擇器返回一些不是 Selenium Python 的數(shù)據(jù)

谷歌地圖一些 XPATH 選擇器返回一些不是 Selenium Python 的數(shù)據(jù)

湖上湖 2023-06-20 17:22:39
我試圖抓取谷歌地圖。phone 和 hours 變量不返回任何數(shù)據(jù)。其他變量工作正常并返回數(shù)據(jù)。XPATH 是正確的。我不確定這里有什么問題。其他選擇器(如姓名、地址、職務(wù)、網(wǎng)站)可以正常返回數(shù)據(jù),但電話和營業(yè)時間不會返回任何數(shù)據(jù)。希望得到一些答案。from selenium import webdriverfrom selenium.webdriver.support.ui import WebDriverWaitfrom selenium.webdriver.common.by import Byfrom selenium.webdriver.support import expected_conditions as ECfrom selenium.common.exceptions import TimeoutExceptionfrom selenium.webdriver.support.ui import Selectfrom selenium.webdriver.common.action_chains import ActionChainsfrom selenium.webdriver.common.keys import Keysfrom scrapy.selector import Selectorimport csvfrom tqdm import tqdmimport timedriver = webdriver.Firefox()linksFile=open("links.txt",'r')allLinks = linksFile.readlines()? ??for link in tqdm(allLinks):? ? try:? ? ? ? driver.get(link)? ? except Exception:? ? ? ? print('Something went wrong with the URL: ')? ??? ? # time.sleep(15)? ??? ? while True:? ? ? ? WebDriverWait(driver, 15).until(? ? ? ? ? ? EC.presence_of_element_located((By.XPATH, '//div[contains(text(), "Directions")] | //div[contains(text(), "Website")]'))? ? ? ? )? ? ? ? results = driver.find_elements_by_xpath('//div[contains(text(), "Directions")] | //div[contains(text(), "Website")]')? ? ? ? for result in results:? ? ? ? ? ? # writing to the CSV file? ? ? ? ? ? outFile =? open("data.csv",'a+',newline="")? ? ? ? ? ? writer = csv.writer(outFile)? ? ? ? ? ? business = driver.find_element_by_xpath('//div[@role="heading"]/div')? ? ? ? ? ? business.click()? ? ? ? ? ? # waiting for the page to load? ? ? ? ? ? WebDriverWait(driver, 15).until(? ? ? ? ? ? ? ? EC.presence_of_element_located((By.XPATH, '//div[@class="immersive-container"]'))? ? ? ? ? ? )
查看完整描述

1 回答

?
月關(guān)寶盒

TA貢獻(xiàn)1772條經(jīng)驗 獲得超5個贊

您可以使用 Java 腳本 outerHTML intead of pageSource 嗎?

response = Selector( driver.execute_script("return document.documentElement.outerHTML"))

在小時的 xpath 中也有一個問題:

hours = response.xpath('//a[contains(text(), "Hours")]/parent::span/following-sibling::div/label/span//b/text()').get()



查看完整回答
反對 回復(fù) 2023-06-20
?
動漫人物

TA貢獻(xiàn)1815條經(jīng)驗 獲得超10個贊

查看完整回答
反對 回復(fù) 2023-06-20
  • 1 回答
  • 0 關(guān)注
  • 178 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號