提取数据的X Path问题



我必须写xpath以获取发布

<div class="lpadding20" style="font-weight: normal;">
<strong>Published: </strong>6/11/2019 at 8:02 AM.
This list includes 414 eligible players.
</div>

您还可以使用split((函数来完成任务

str = 'published = 6/11/2019 at 8:02 AM'
str=str.split('=')
str=str[1].split('at')
print('published date =',str[0],'npublished time =',str[1])

您将获得相同的结果

这个简单的表达可能会在这里工作:

publisheds*=s*(.+?)s*ats*(.+)s*

在此演示中,如果您有兴趣,可以解释该表达式。

测试

import re
regex = r"publisheds*=s*(.+?)s*ats*(.+)s*"
test_str = "published = 6/11/2019 at 8:02 AM"
subst = "published date = \1\npublished time = \2"
# You can manually specify the number of replacements by changing the 4th argument
result = re.sub(regex, subst, test_str, 0, re.MULTILINE)
if result:
    print (result)

最新更新