|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
from selenium import webdriver # 导入浏览器驱动模块
from selenium.webdriver.support.wait import WebDriverWait # 导入等待类
from selenium.webdriver.support import expected_conditions as EC # 等待条件
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
# 节点定位
try:
# 创建谷歌浏览器驱动参数对象
chrome_options = webdriver.ChromeOptions()
# 不加载图片
prefs = {"profile.managed_default_content_settings.images": 2}
chrome_options.add_experimental_option("prefs", prefs)
# 使用headless无界面浏览器模式
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-gpu')
# 加载谷歌浏览器驱动
s= Service(r'F:\pythonProject1\chromedriver.exe')
driver = webdriver.Chrome(options=chrome_options,service=s)
# 请求地址
driver.get('https://item.jd.com/12353915.html')
wait = WebDriverWait(driver,10) # 等待10秒
# 等待页面加载class名称为m-item-inner的节点,该节点中包含商品信息
wait.until(EC.presence_of_element_located((By.CLASS_NAME,"m-item-inner")))
# 获取name节点中所有div节点
name_div = driver.find_element_by_css_selector('#name').find_elements_by_tag_name('div')
summary_price = driver.find_element_by_id('summary-price')
print('提取的商品标题如下:')
print(name_div[0].text) # 打印商品标题
print('提取的商品宣传语如下:')
print(name_div[1].text) # 打印宣传语
print('提取的编著信息如下:')
print(name_div[4].text) # 打印编著信息
print('提取的价格信息如下:')
print(summary_price.text) # 打印价格信息
driver.quit() # 退出浏览器驱动
except Exception as e:
print('显示异常信息!', e)
以上代码运行时出错,错误代码如下。
显示异常信息! Message:
Stacktrace:
Backtrace:
Ordinal0 [0x003A7413+2389011]
Ordinal0 [0x00339F61+1941345]
Ordinal0 [0x0022C658+837208]
Ordinal0 [0x002591DD+1020381]
Ordinal0 [0x0025949B+1021083]
Ordinal0 [0x00286032+1204274]
Ordinal0 [0x00274194+1130900]
Ordinal0 [0x00284302+1196802]
Ordinal0 [0x00273F66+1130342]
Ordinal0 [0x0024E546+976198]
Ordinal0 [0x0024F456+980054]
GetHandleVerifier [0x00559632+1727522]
GetHandleVerifier [0x0060BA4D+2457661]
GetHandleVerifier [0x0043EB81+569713]
GetHandleVerifier [0x0043DD76+566118]
Ordinal0 [0x00340B2B+1968939]
Ordinal0 [0x00345988+1989000]
Ordinal0 [0x00345A75+1989237]
Ordinal0 [0x0034ECB1+2026673]
BaseThreadInitThunk [0x75DA343D+18]
RtlInitializeExceptionChain [0x77B39812+99]
RtlInitializeExceptionChain [0x77B397E5+54]
是什么原因造成。如何解决。请各位老师帮帮我谢谢了
|
|