Фишки Python
29 subscribers
2 photos
3 files
29 links
Всё что ты хотел узнать, но ленился спросить.

Декораторы, итераторы и контракты.
Download Telegram
Selenium + PhantomJS
Scrapy можно попробовать scrapyjs
import sqlite3
import requests
from lxml import html
from lxml import etree
from datetime import datetime


def log(*s):
print("{0} [LOG]:".format(datetime.now()), *s)


def main():
r = requests.get("https://www.av ito.ru/krasnodar/avtomobili/vaz_lada?view=list&radius=0&s_trg=3&f=188_893b&i=1")
if r.status_code != 200:
log("Status code check fail: {}".format(r.status_code))
tree = html.fromstring(r.text)
res = []
l = tree.xpath('//div[@itemtype="http://sch ema.org/Product"]')
for p in l:
id = p.attrib.get('id')
price = p.xpath('.//p[@itemprop="price"]')[0].attrib.get('content')
mileage = p.xpath('div[@class="mileage"]')[0].text
desc = p.xpath('meta[@itemprop="description"]')[0].attrib.get('content')
res.append((id, mileage, desc))


if name == "main":
main()
Jupyter Notebook

python -m pip install --upgrade pip
python -m pip install jupyter

pip install numpy pandas scikit-learn matplotlib seaborn

jupyter notebook
Python для сложных задач (ru) Дж. Вандер Плас
IPython, NumPy, Pandas, Matplotlib, Scikit-Learn
NumPy — для работы с однородными данными в виде массивов
Pandas — для работы с неоднородными и поименованными данными
SciPy — для общих научных вычислительных задач
Matplotlib — для визуализаций типографского качества
IPython — для интерактивного выполнения и совместного использования кода
Scikit-Learn — для машинного обучения и множества других инструментов
Jupyter - автодополнение по Tab (It will also complete filenames in the current directory)
? -> Introduction and overview of IPython's features (this screen).
object? -> Details about 'object'.
object?? -> More detailed, verbose information about 'object'.
%quickref -> Quick reference of all IPython specific syntax and magics.
help -> Access Python's own help system.
%magic for information on the magic subsystem
%hist - история команд
!ls или !dir - запуск команды в системной оболочке
_ih - список последних команд, _i - запуск последней команды, _ii - предпоследней и т.д.
_oh - output history, _ - предыдущий вывод, __ - предпредыдущий
_dh - directory history
?datetime.*t* - list of all items in object with t
Line magics take a single % and cell magics are prefixed with two %%
%timeit x=10 : time the 'x=10' statement with high precision.

%%timeit x=2**100
x**100
Time 'x**100' with a setup of 'x=2**100'; setup code is not counted. This is an example of a cell magic.
cp ${f}.txt $bar : Variable expansion in magics and system commands