Python HTMLParser

How to spent two days if you know nothing about Python: need parse HTML page code, where VK id and username of every person who shared post stores   with open(‘test.html’, ‘r’, encoding=’utf-8′) as content_file: read_data = content_file.read() from html.parser import HTMLParser import re class MyHTMLParser(HTMLParser): def handle_starttag(self, tag, attrs): vk_id = str(attrs) for line in vk_id: vk = re.findall(‘/\S+$’, vk_id) vk_fnd = str(vk) if re.search(‘/\w+\’\)\]’, vk_fnd): global vk_read vk_read = vk_fnd for ch in [‘/’, ‘)’, ‘[‘, ‘]’, ‘”‘, “‘”]: if ch in vk_read: vk_read = vk_read.replace(ch, “”) def handle_data(self, data): global vk_name vk_name = str(data) assert isinstance(data, object) for line in vk_name: if re.match(‘\S+\s+\S+$’, vk_name): print(“@{0} – {1}”.format(vk_read, vk_name)) break parser = MyHTMLParser() parser.feed(read_data) Now I know more.Short Read more…

Plone installation

Will try to use Plone CMS for test cases, interesting to see what and how CMS on Python worked. Start here: https://plone.org/documentation/manual/installing-plone/installation-quick-guide For Python: Guide and I’ve use only one part from it here. I’ve done everything as guided above. [root@web Python-2.7.6]# ls -ltr /usr/bin/python* -rwxr-xr-x. 2 root root 4864 Jan 22 2014 /usr/bin/python2.6 -rwxr-xr-x. 2 root root 4864 Jan 22 2014 /usr/bin/python lrwxrwxrwx. 1 root root 6 Nov 2 15:46 /usr/bin/python2 -> python [root@web Python-2.7.6]# ls -ltr /usr/local/bin/python* -rwxr-xr-x. 1 root root 6214493 Apr 20 11:44 /usr/local/bin/python2.7 -rwxr-xr-x. 1 root root 1674 Apr 20 11:48 /usr/local/bin/python2.7-config [root@web Python-2.7.6]# echo $PATH /usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin [root@web Python-2.7.6]# which python /usr/bin/python [root@web Python-2.7.6]# sudo sh sh-4.1# which python /usr/bin/python sh-4.1# python Python 2.6.6 (r266:84292, Jan 22 2014,Short Read more…

Заводим питончика дома или установка Python на Centos 6

Хороший гайд здесь: https://github.com/h2oai/h2o/wiki/Installing-python-2.7-on-centos-6.3.-Follow-this-sequence-exactly-for-centos-machine-only How to install Python 2.7.6 on CentOS 6.3 (6.2 and 6.4 okay too, probably others) stolen from Daniel Eriksson. Thanks Daniel! http://toomuchdata.com/2012/06/25/how-to-install-python-2-7-3-on-centos-6-2/ (modified a little) CentOS 6.2 ships with Python 2.6.6 and depends on that specific version. Be careful not to replace it or bad things will happen. If you need access to a newer version of Python you must compile it yourself and install it side-by-side with the system version. Here are the steps necessary to install Python 2.7.6. Execute all the commands below as root. Either log in as root temporarily or use sudo. Install development tools In order to compile Python you must first install the development tools: yum groupinstall “Development tools” You alsoShort Read more…

Python array

Начинаю учить Пайтон, буду набивать шпаргалки. lst = [‘spam’, ‘drums’, 100, 1234] print(lst[2]) 100 Это мой первый массив, детка. Спустя время, это может показаться для меня смешным, но сейчас я очень доволен собой. Read more…