Monday, 15 February 2010

python - BeautifulSoup get an attribute from a find -


I'm very new to the dragon, so first of all, sorry, I print href content from any selection created with search I want to do () beautiful method but I can not do it and I do not know why I have done this. Import from imported soup from imported import soup of payload = {'btnSubmit': 'Login', 'username': 'xxx', 'password': 'xxx'} with session (): c: post ('http://www.xxx.xxx/login.php', data = Payload) request = c.get ('http: // www .xxx.xxx / xxxx ') soup = beautiful soup (request.content) row_int = soup.find (' td ', attrs = {' class': 'rnr-cc rnr-bc rnr-icons'}) print row_int [ 'Href']

but I have this error

  traceback (most recent call final): File "& lt; pyshell # 14" gt ; Line 1, & lt; Module & gt; Execfile ('C: \ Users \ Francesco \ Desktop \ prova.py') File "C: \ Users \ Francesco \ Desktop \ prova.py", line 15, & lt; Module & gt; Print line_ant ['href'] file "c: \ Python 27 \ site-packages \ bs4 \ element.py", in line 905, __getitem__ back in itself .attrs [key] KeyError: 'href'  < / Pre_> 

row_int content is like this:

  [class = "Rnr-button-img" data-mark = "view" href = "xxxxxxx" id =   

link between td tag ( a element):

line = soup.fund ('td', etters = {'class':' rnr-cc rnr-bc rnr-ick S '}) a = row.find (' a ', href = true) If one: a [' href ']

in the soup or, cum with:

  Print. Selection ('Td.rnr-cc.rnr-bc.rnr-icons a [href]'): Print a [[href]]  

No comments:

Post a Comment