Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #81818
| Newsgroups | comp.lang.python |
|---|---|
| Date | 2014-12-02 14:40 -0800 |
| References | <mailman.16010.1416476438.18130.python-list@python.org> |
| Message-ID | <401fd34b-4671-455a-8496-a3aa9b6af74b@googlegroups.com> (permalink) |
| Subject | Re: python 2.7 and unicode (one more time) |
| From | Simon Evans <musicalhacksaw@yahoo.co.uk> |
Hi Peter Otten re: ---------------------------------------------------------------------------- There is no assignment soup_atag = whatever but there is one to atag. The whole session should when you omit the offending line > atag = soup_atag.a or insert soup_atag = soup before it. ---------------------------------------------------------------------------- Python 2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)] on win 32 Type "help", "copyright", "credits" or "license" for more information. >>> import urllib2 >>> from bs4 import BeautifulSoup >>> html_atag = """<html><body><p>Test html a tag example</p> ... <a href="http://www.packtpub.com'>Home</a> ... <a href="http;//www.packtpub.com/books'.Books</a> ... </body> ... </html>""" >>> soup = BeautifulSoup(html_atag,'lxml') >>> atag = soup.aprint(atag) >>> atag = soup.a >>> print(atag) <a href="http://www.packtpub.com'>Home</a> <a href=" http=""> </a> >>> type(atag) <class 'bs4.element.Tag'> >>> tagname = atag.name >>> print tagname a >>> atag.name = 'p' >>> print (soup) <html><body><p>Test html a tag example</p> <p href="http://www.packtpub.com'>Home</a> <a href=" http=""> </p></body> </html> >>> atag.name = 'p' >>> print(soup) <html><body><p>Test html a tag example</p> <p href="http://www.packtpub.com'>Home</a> <a href=" http=""> </p></body> </html> >>> atag.name = 'a' >>> print(soup) <html><body><p>Test html a tag example</p> <a href="http://www.packtpub.com'>Home</a> <a href=" http=""> </a></body> </html> >>> soup_atag = soup >>> atag = soup_atag.a >>> print (atag['href']) http://www.packtpub.com'>Home</a> <a href= >>> ---------------------------------------------------------------------------- Thank you. Yours Simon.
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
python 2.7 and unicode (one more time) Francis Moreau <francis.moro@gmail.com> - 2014-11-20 10:40 +0100 Re: python 2.7 and unicode (one more time) Simon Evans <musicalhacksaw@yahoo.co.uk> - 2014-12-02 14:40 -0800
csiph-web