提问人:Sergei Ivanitsa 提问时间:10/29/2023 更新时间:10/29/2023 访问量:30
使用硒从中国网站收集数据
Collecting data from a Chinese website using selenium
问:
我从事的是用Selenium从网站 https://m.guazi.com/detail?clueId=129125011 收集数据的业务,我遇到了这个问题,在带有汽车成本的标签中,我看到了一些奇怪的符号
<span class="price-num gzfont" data-v-68ea11d6="">.万</span>
同时,浏览器中页面本身的一切看起来都很正常
这是我的代码
from selenium import webdriver
import time
from chromedriver_py import binary_path
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
svc = webdriver.ChromeService(executable_path=binary_path)
options = webdriver.ChromeOptions()
options.add_argument("user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.5845.888 YaBrowser/23.9.2.888 Yowser/2.5 Safari/537.36")
driver = webdriver.Chrome(service=svc, options=options)
url = "https://www.guazi.com/buy"
try:
driver.get(url=url)
time.sleep(5)
element = driver.find_element(By.XPATH, "/html/body/div/div/div/div[1]/div[3]/div[1]/div[2]/div[1]/div[2]/div[1]/div[1]/span[10]")
element.click()
time.sleep(5)
element = driver.find_element(By.XPATH, "/html/body/div/div/div/div[1]/div[3]/div[1]/div[2]/div[2]/div[2]/div[1]/div[1]/span[11]")
element.click()
time.sleep(5)
element = driver.find_element(By.CLASS_NAME, "car-card.content-item")
element.click()
time.sleep(10)
driver.switch_to.window(driver.window_handles[1])
time.sleep(5)
element = driver.find_element(By.CSS_SELECTOR, "#pageWrapper > div.pc-detail > div.center.js-center.detail > div.infor-main.clearfix.service-open > div.product-textbox > div.pricebox.js-disprice > div.price-main > span")
price = element.text
print(price)
except Exception as ex:
print(ex)
finally:
driver.close()
driver.quit()
你能告诉我问题可能与什么有关吗?它与 UTF-8 编码有关吗?还是开发人员的一些棘手的加密? 这个问题不仅会影响成本,还会影响汽车卡中的所有其他数字(发布日期、里程等)。
附言
当我尝试在Firefox中打开页面时,我注意到这些符号代替了几分之一秒的成本。
我想获取汽车价值数据并将其保存到 json 字典中,但我看到的不是数字,而是一些晦涩难懂的字符
答: 暂无答案
评论