0
私のファイルは、貴様のURLを持っています:期待される文字列またはその他の文字バッファオブジェクト
www.example.com
www.example.com/validagain
www.example.com/search?q=jsdajasj;kdas --> trying to get rid off
www.example.com/anothervalid
私が使用して/search
を分離することができました正規表現:
import re
generate_links = re.compile('http://(.*)') #compile all http links
generate_links2 = re.compile('(.*)/eng/(.*)') #compile all english url
with open ("VAC\queue.txt", "r") as queued_list, open('newqueue.txt','w') as queued_list_updated:
for links in queued_list:
url = ""
services_url = ""
valid_url = ""
match = generate_links2.search(links)
if match is not None:
url = match.group()
generate_links3 = re.compile('(.*)/services/(.*)') #compile all services links
match2 = generate_links3.search(links)
if match2 is not None:
services_url = match2.group()
print services_url
generate_links4 = re.compile('(.*)/search?(.*)') #compiled error links
match3 = generate_links4.search(links) #matched all error links
しかし、どのように私は自分自身を削除するために戻ってservices_url
からmatch3
変数を使用するか、または交換すること?
ので期待される結果は次のようになります。
www.example.com
www.example.com/validagain
www.example.com/anothervalid