您好我有一个问题:如何从网站引用课程但不写课程中的完整文本。这是我想要参考的课程。
<div class="nm-engine-item nm-check-list-item nm-j-configurator-item nm-j-configurator-status_11000 nm-j-configurator-item-forceselectable" data-configurator-id="8XFASG0" data-filter-criteria-fueltype="benzin" data-filter-criteria-gear="S tronic" data-filter-criteria-trimline="trimline_default" data-filter-criteria-drive="Framhjulsdrift" data-configurator-group="id_a1sb_engines" data-message="" data-mbvid="8XFASG\0-51027\2017"> </div>
<div class="nm-engine-item nm-check-list-item nm-j-configurator-item nm-j-configurator-status_11010 nm-j-configurator-item-forceselectable" data-configurator-id="8XFBSG0" data-filter-criteria-fueltype="benzin" data-filter-criteria-gear="S tronic" data-filter-criteria-trimline="trimline_sport" data-filter-criteria-drive="Framhjulsdrift" data-configurator-group="id_a1sb_engines" data-message="" data-mbvid="8XFBSG\0-51027\2017"></div>
就像你可以看到除了11010和11000之外的类是相同的。因此在我的代码中我必须写2 For For Sector来抛出那些类。还有其他选择吗? 类似的东西:
对于每个configurator_id(0)在engine_list.classname中,例如“nm-engine-item nm-check-list-item nm-j-configurator-item nm-j-configurator-status _ *”
代码可以工作,但如果有类似的东西可以改善
For Each engine_list In doc.GetElementsByClassName("clearfix nm-md-engine-selection-group")
'wsNew.Cells(2, 1).Value = engine_list.innerText
hubraum_o = engine_list.GetElementsByClassName("nm-el-hdl nm-el-hdl-03 nm-at-hdl-b")
hubraum = hubraum_o.innerText
'Debug.Print hubraum
For Each configurator_id(0) In engine_list.GetElementsByClassName("nm-engine-item nm-check-list-item nm-j-configurator-item nm-j-configurator-status_11010 nm-j-configurator-item-forceselectable")
mbv(0) = configurator_id(0).getAttribute("data-configurator-id")
mbv_6(0) = Left(mbv(0), 6)
'Debug.Print mbv_6(0)
trimline(0) = configurator_id(0).getAttribute("data-filter-criteria-trimline")
'Debug.Print trimline(0)
preis_o(0) = configurator_id(0).GetElementsByClassName("nm-el-pg nm-el-pg-04 nm-j-configurator-text-price")
preis(0) = preis_o(0).innerText
'Debug.Print preis(0)
co2_o(0) = configurator_id(0).GetElementsByClassName("nm-EngineEmission nm-el-pg nm-el-pg-04")
co2(0) = co2_o(0).innerText
'Debug.Print co2(0)
kw_o(0) = configurator_id(0).GetElementsByClassName("nm-Power nm-el-pg nm-el-pg-04")
kw(0) = kw_o(0).innerText
'Debug.Print kw(0)
wsNew.Cells(zc_audi, 1).Value = mbv_6(0)
wsNew.Cells(zc_audi, 2).Value = "Land MBV"
wsNew.Cells(zc_audi, 3).Value = modell & "-" & modell_links
wsNew.Cells(zc_audi, 4).Value = trimline(0)
wsNew.Cells(zc_audi, 5).Value = kw(0)
wsNew.Cells(zc_audi, 6).Value = hubraum
wsNew.Cells(zc_audi, 7).Value = co2(0)
wsNew.Cells(zc_audi, 8).Value = preis(0)
mbv_6(0) = Empty
trimline(0) = Empty
kw(0) = Empty
co2(0) = Empty
preis(0) = Empty
zc_audi = zc_audi + 1
Next configurator_id(0)
For Each configurator_id(1) In engine_list.GetElementsByClassName("nm-engine-item nm-check-list-item nm-j-configurator-item nm-j-configurator-status_11000 nm-j-configurator-item-forceselectable")
mbv(1) = configurator_id(1).getAttribute("data-configurator-id")
mbv_6(1) = Left(mbv(1), 6)
'Debug.Print mbv_6(1)
trimline(1) = configurator_id(1).getAttribute("data-filter-criteria-trimline")
'Debug.Print trimline(1)
preis_o(1) = configurator_id(1).GetElementsByClassName("nm-el-pg nm-el-pg-04 nm-j-configurator-text-price")
preis(1) = preis_o(1).innerText
'Debug.Print preis(1)
co2_o(1) = configurator_id(1).GetElementsByClassName("nm-EngineEmission nm-el-pg nm-el-pg-04")
co2(1) = co2_o(1).innerText
'Debug.Print co2(1)
kw_o(1) = configurator_id(1).GetElementsByClassName("nm-Power nm-el-pg nm-el-pg-04")
kw(1) = kw_o(1).innerText
'Debug.Print kw(1)
wsNew.Cells(zc_audi, 1).Value = mbv_6(1)
wsNew.Cells(zc_audi, 2).Value = "Land MBV"
wsNew.Cells(zc_audi, 3).Value = modell & "-" & modell_links
wsNew.Cells(zc_audi, 4).Value = trimline(1)
wsNew.Cells(zc_audi, 5).Value = kw(1)
wsNew.Cells(zc_audi, 6).Value = hubraum
wsNew.Cells(zc_audi, 7).Value = co2(1)
wsNew.Cells(zc_audi, 8).Value = preis(1)
mbv_6(1) = Empty
trimline(1) = Empty
kw(1) = Empty
co2(1) = Empty
preis(1) = Empty
zc_audi = zc_audi + 1
Next configurator_id(1)