Posts

Showing posts with the label Python

Dealing with "smart" quotes and other HTML annoyances when parsing HTML text using Python and BeautifulSoup

I've recently been writing some homegrown scripts to parse web pages and do something useful with the information using Python 2.7 and the BeautifulSoup library.  This involves printing the output to a terminal (e.g. Gnome Terminal) where the output is hopefully human readable but in some cases was not. The most common issue I ran into were various forms of "smart quotes" and similar html annoyances. If this is not properly handled you'll get output like John X s Blog (where X is the following 7 character group without the intervening spaces - hard to display it verbatim in the blogger environment!)  & # 8 2 1 7 ;  or even John X s Blog   (where X is some awkward block symbol that can't be adequately described or rendered here. This actually results from the MS quote being "decoded" as Latin-1 - so it's sort of a cascade of errors.) The first of these is known as an "HTML entity" and here is a list of them .  ...

Deja Dup thinks current computer name is bar but it should be foo

Fedora 17 x86_64 - running the "Backup" utility aka Deja Dup. Set it up previously and ran at least one backup. Now a regularly scheduled backup starts and get an error message along the lines of "Computer Name Changed" "The existing backup is of a computer named foo but the current computer's name is bar. If this is unexpected you should backup to a different location". In my case the actual (incorrect) name of the "current computer" was something like 12-34-56-78.tvc-ip.com which made absolutely no sense at all.  (I made up the numbers which represent an ip address but the tvc-ip.com is what it really said). So what gives? "Backup" is really "Deja-Dup". "Deja-Dup is really a GUI front end for "Duplicity". "Duplicity" is apparently written in Python. When Python decides to figure out the current computer's name, it calls                           socket.getfqdn() So I ...