【发布时间】:2018-02-14 13:03:23
【问题描述】:
我正在尝试遍历一个长列表(我们称之为url_list),其中每个项目看起来像:
<a href="https://www.example.com/5th-february-2018/" itemprop="url">5th February 2018</a>,
<a href="https://www.example.com/4th-february-2018/" itemprop="url">4th February 2018</a>,
<a href="https://www.example.com/3rd-february-2018/" itemprop="url">3rd February 2018</a>,
<a href="https://www.example.com/2nd-february-2018/" itemprop="url">2nd February 2018</a>,
等等。我想遍历列表并只保留前两个引号之间的文本,并丢弃其余的 - 即:
https://www.example.com/5th-february-2018/,
https://www.example.com/4th-february-2018/,
https://www.example.com/3rd-february-2018/,
https://www.example.com/2nd-february-2018/,
所以基本上我试图返回一个很好的干净的 url 列表。我没有太多运气遍历列表并拆分引号 - 有没有更好的方法来做到这一点?有没有办法把itemprop=字符串后面的所有东西都扔掉?
【问题讨论】:
标签: python regex list text-parsing