使用css选择器从html页面提取信息
我想使用css选择器从html页面(见下文)中选择一些信息,如“Room1”、“Room2”、“Room3”,并将其打印为“How can do that?”:使用css选择器从html页面提取信息,html,css,select,Html,Css,Select,我想使用css选择器从html页面(见下文)中选择一些信息,如“Room1”、“Room2”、“Room3”,并将其打印为“How can do that?”: 我的信息 房间1:续租 房间2:30平方米 房间3:2平方米 房间4:4 房间5:5 您可以使用以下命令 Nodes = document.querySelectorAll(".bloco-dados li") Data = [] // new array for (I = 0; I < Nodes.length;
我的信息
-
房间1:续租
-
房间2:30平方米
-
房间3:2平方米
-
房间4:4
-
房间5:5
您可以使用以下命令
Nodes = document.querySelectorAll(".bloco-dados li")
Data = [] // new array
for (I = 0; I < Nodes.length; I++) {
DataName = Nodes[I].firstChild.innerText // <b> tag is the first child node of <li> tag
DataName = DataName.substr(0, DataName.length - 1) // Remove last character (the colon)
DataValue = Nodes[I].lastChild.innerText // <span> tag is the last child node of <li> tag
Data[DataName] = DataValue
}
alert(Data["Room 1"])
alert(Data["Room 2"])
alert(Data["Room 3"])
alert(Data["Room 4"])
alert(Data["Room 5"])
Nodes=document.queryselectoral(“.bloco-dados-li”)
Data=[]//新数组
对于(I=0;I标记的第一个子节点
DataName=DataName.substr(0,DataName.length-1)//删除最后一个字符(冒号)
DataValue=Nodes[I].lastChild.innerText//tag是标记的最后一个子节点
数据[DataName]=数据值
}
警报(数据[“1号房间])
警报(数据[“2号房间])
警报(数据[“3号房间])
警报(数据[“4号房间])
警报(数据[“5号房间])
使用什么语言?你尝试过什么?CSS本身无法做到这一点。。。例如,使用javascript,看看document.querySelector('ul.bloco-dados li b').textContent
或queryselectoral()
我是css的初学者,所以你能在一些步骤中帮助我吗?我应该没有特殊的语言。我只想在HTML中选择一些信息。我做了一些搜索,但因为我是css SELECTOR的初学者,并且没有使用css SELECTOR的经验,所以我真的需要您的帮助。我希望通过以下结构指定Room1、Room2或Room3来获取内部标记:Selector1=“WRITE SELECTOR HERE(Room1)”Selector2=“WRITE SELECTOR HERE(Room2)”然后按照以下格式打印它们:print('Room1:{}.format(tree.cssselect(Selector_1)[0].text])print('')其中“tree”来自此代码:从lxml导入html,etree打开(r'listing.html',“r”)为f:page=f.read()tree=html.fromstring(page)
Nodes = document.querySelectorAll(".bloco-dados li")
Data = [] // new array
for (I = 0; I < Nodes.length; I++) {
DataName = Nodes[I].firstChild.innerText // <b> tag is the first child node of <li> tag
DataName = DataName.substr(0, DataName.length - 1) // Remove last character (the colon)
DataValue = Nodes[I].lastChild.innerText // <span> tag is the last child node of <li> tag
Data[DataName] = DataValue
}
alert(Data["Room 1"])
alert(Data["Room 2"])
alert(Data["Room 3"])
alert(Data["Room 4"])
alert(Data["Room 5"])