目标网址: http://ggzyjy.jl.gov.cn/JiLinZtb//Template/Default/MoreInfoJYXX.aspx?CategoryNum=004002在gooseeker 可以解析到数据,但在python中使用获取不到数据

doc = etree.HTML(content)
bbsExtra = GsExtractor()
bbsExtra.setXsltFromFile("jl.xml")
result = bbsExtra.extract(doc)
返回数据如下:[size=17.0667px]<?xml version="1.0"?><zhaobiao2/>
数据规则如下
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
<xsl:template match="/">
<zhaobiao2>
<xsl:apply-templates select="//*[@id='DataList1']/tbody/tr[position()>=2 and ((position()-2) mod 2)=0 and count(./td[position()=2]/a/@title)>0 and count(./td[position()=2]/a/@href)>0 and count(./td[position()=5]/text())>0]" mode="zhaobiao2"/>
</zhaobiao2>
</xsl:template>
<xsl:template match="//*[@id='DataList1']/tbody/tr[position()>=2 and ((position()-2) mod 2)=0 and count(./td[position()=2]/a/@title)>0 and count(./td[position()=2]/a/@href)>0 and count(./td[position()=5]/text())>0]" mode="zhaobiao2">
<item>
<title>
<xsl:value-of select="td[position()=2]/a/@title"/>
</title>
<url>
<xsl:value-of select="td[position()=2]/a/@href"/>
</url>
<create_date>
<xsl:value-of select="td[position()=5]/text()"/>
</create_date>
</item>
</xsl:template>
</xsl:stylesheet>
举报 使用道具
| 回复

共 2 个关于本帖的回复 最后回复于 2018-4-13 16:33

cluetest21 初级会员 发表于 2018-4-13 16:32:22 | 显示全部楼层
技术人员会在周末测试
举报 使用道具
anteam 新手上路 发表于 2018-4-13 16:33:45 | 显示全部楼层
找到问题了:
<xsl:template match="//*[@id='DataList1']/tbody/tr[position()>=2 and ((position()-2) mod 2)=0 and count(./td[position()=2]/a/@title)>0 and count(./td[position()=2]/a/@href)>0 and count(./td[position()=5]/text())>0]" mode="zhaobiao2">

去除 tbody 即可:
<xsl:template match="//*[@id='DataList1']/tr[position()>=2 and ((position()-2) mod 2)=0 and count(./td[position()=2]/a/@title)>0 and count(./td[position()=2]/a/@href)>0 and count(./td[position()=5]/text())>0]" mode="zhaobiao2">

之前写xpath  规则时,也遇到过类式问题,有时 tbody识别不了。


举报 使用道具
您需要登录后才可以回帖 登录 | 立即注册

精彩推荐

  • Gephi社会网络分析-马蜂窝游记文本分词并同
  • Gephi社会网络分析-基于马蜂窝游记文本以词
  • 知乎话题文本根据词语间距筛选后生成共词矩
  • 马蜂窝游记文本分词后以词语间距为筛选条件
  • 学习使用apriori算法挖掘关联关系

热门用户

GMT+8, 2024-3-28 19:53