Какую аутентификацию вы используете? Если это проверка подлинности форм, то в лучшем случае вам нужно будет найти файл cookie .ASPXAUTH и передать его в запросе WebClient
.
В худшем случае это не сработает.
Это регулярное выражение должно работать для вас \s+(?=[^()]*(?:\(|$))
result = re.split(r"\s+(?=[^()]*(?:\(|$))", subject)
Объяснение
r"""
\s # Match a single character that is a “whitespace character” (spaces, tabs, and line breaks)
+ # Between one and unlimited times, as many times as possible, giving back as needed (greedy)
(?= # Assert that the regex below can be matched, starting at this position (positive lookahead)
[^()] # Match a single character NOT present in the list “()”
* # Between zero and unlimited times, as many times as possible, giving back as needed (greedy)
(?: # Match the regular expression below
# Match either the regular expression below (attempting the next alternative only if this one fails)
\( # Match the character “(” literally
| # Or match regular expression number 2 below (the entire group fails if this one fails to match)
$ # Assert position at the end of a line (at the end of the string or before a line break character)
)
)
"""
Я бы попытался использовать положительное утверждение.
r'(?<=\))\s+'
Пример:
>>> import re
>>> result = re.split(r'(?<=\))\s+', 'type("book") title("golden apples") pages(10-35 70 200-234) comments("good read")')
>>> result
['type("book")', 'title("golden apples")', 'pages(10-35 70 200-234)', 'comments(
"good read")']
test test test
.
– Narendra Yadala
10 March 2012 в 09:58
Разделить на ") "
и добавить )
к каждому элементу, кроме последнего.
re.split(r"\s+(?=[^()]*(?:\(|$))", subject)
– San4ez 10 March 2012 в 09:50