在Python中找到字符串中的url副本

时间:2015-06-24 04:58:51

标签: python regex

有人可以提供帮助。作为一个例子,下面的文本输出有超过pne超链接。我正在寻找第一个输出: JournalEntries.dox?method = view& number = JE-00000725

Here are my output source and i look for these ones **https://www.zuora.com/apps/JournalEntries.dox?method=view&number=JE-00000725**

    https://www.zuora.com/apps/JournalEntries.dox?method=view&number=JE-00000726
https://www.zuora.com/apps/javascript:downloadTansactions("JournalEntries.dox?method=downloadTransactions&number=JE-00000726");
https://www.zuora.com/apps/AccountingPeriods.dox?method=view&id=2c92a0f949efde7f0149f05314e640b6
https://www.zuora.com/apps/ChartOfAccountsSetting.do?method=edit&id=2c92a0fb43812a1a0143980f213b7e34
https://www.zuora.com/apps/ChartOfAccountsSetting.do?method=edit&id=2c92a0fb43812a1a0143980f21507e39
https://www.zuora.com/apps/JournalEntries.dox?method=view&number=JE-00000725
https://www.zuora.com/apps/javascript:downloadTansactions("JournalEntries.dox

1 个答案:

答案 0 :(得分:0)

我将其保存在名为" url":

的文件中
https://www.zuora.com/apps/JournalEntries.dox?method=view&number=JE-00000725**
https://www.zuora.com/apps/JournalEntries.dox?method=view&number=JE-00000726
https://www.zuora.com/apps/javascript:downloadTansactions("JournalEntries.dox?method=downloadTransactions&number=JE-00000726");
https://www.zuora.com/apps/AccountingPeriods.dox?method=view&id=2c92a0f949efde7f0149f05314e640b6
https://www.zuora.com/apps/ChartOfAccountsSetting.do?method=edit&id=2c92a0fb43812a1a0143980f213b7e34
https://www.zuora.com/apps/ChartOfAccountsSetting.do?method=edit&id=2c92a0fb43812a1a0143980f21507e39
https://www.zuora.com/apps/JournalEntries.dox?method=view&number=JE-00000725
https://www.zuora.com/apps/javascript:downloadTansactions("JournalEntries.dox

现在我的代码如下:

import re
f = open ("url", "r").readlines()
for i in f:
    if re.search("JournalEntries\.dox\?method\=view\&number\=JE\-00000725",i): 
        print "found it !!"