【发布时间】:2016-09-23 20:31:48
【问题描述】:
https://en.wikipedia.org/wiki/List_of_largest_companies_by_revenue
我正在尝试按收入顺序查找公司名称。这有点挑战性,因为标题都有不同格式的标签。如果有人能提出解决方案,我将不胜感激。
我的问题的一个例子:
我想匹配“Wal-Mart Stores Inc.”然后是“中石化集团”,依次类推。
<td><a href="/wiki/Wal-Mart_Stores,_Inc." title="Wal-Mart Stores, Inc."class="mw-redirect">Wal-Mart Stores, Inc.</a></td>
...在文档中进一步...
<td style="background: #ffffcc;"><a href="/wiki/Sinopec_Group" title="Sinopec Group" class="mw-redirect">Sinopec Group</a></td>
提前致谢。
【问题讨论】:
-
首先,您可能不需要正则表达式。其次,看起来他们都是
mw-redirect类的锚点......像BeautifulSoup这样的东西应该能够根据它来选择项目...... -
我知道我应该使用
BeautifulSoup,尽管我需要使用正则表达式。 -
为什么不使用原始数据呢?