Mechanize-Browser question..

B

bruce

hi..

i have the following piece of test code. i'm trying to implement/check out
the follow-link method. i'm just trying to figure out how to get a link from
the page.

i was hoping that the regex would basically get the 1st url link...

any thoughts/comments/ideas as to what i'm doing wrong.

thanks

-bruce

br = Browser()
br.set_handle_redirect(True)
br.set_handle_referer(True)
br.open(url2)
#br.set_cookiejar(cj)
br.set_debug_redirects(True)
# Log HTTP response bodies (ie. the HTML, most of the time).
br.set_debug_responses(True)
# Print HTTP headers.
br.set_debug_http(True)
r2 = br.follow_link(url_regex=re.compile(r"\*"),nr=1) <<<<<<<<<<<<<<<

response = br.response() # this is a copy of response
print response.read()
 
T

Tal Einat

bruce said:
r2 = br.follow_link(url_regex=re.compile(r"\*"),nr=1) <<<<<<<<<<<<<<<

Seems to me your regex is buggy. You are using a "raw string" yet you
still escape the asterisk ('*') with a backslash? This will only match
a string which contains an asterisk, while I'm guessing you're tring to
match all strings.

Try removing the backslash.


P.S. In future postings, be more verbose: What are you trying to do?
What is the unexpected behavior that you are seeing? etc.

- Tal
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top