基础知识 匿名函数lambda
字符串String 1 2 3 4 5 6 7 a = r'print("\")' print (a)s.isdigit() s.isupper() s.islower()
字符串切片 1 2 3 4 s = "hello world" print (s[0 ::2 ])
列表List 1 2 3 4 5 6 list = [1 ,2 ,3 ,4 ,5 ]ls = [i for i in range (20 )] ls.sort(key,reverse=True )
元组Tuple 1 2 3 4 5 6 7 8 9 10 11 12 13 tuple = (1 ,2 ,3 ,4 )tuple1 = () tuple2 = tuple () tuple3 = (1 ,)
字典Dictionary 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 dict1 = {key1:value1,key2:value2, ...} dict2 = {} dict3 = dict () s = {'a' :1 ,'b' :2 ,'c' :3 } s.items() s,keys() s.values() s.get(key,default)
常用函数 1 2 3 4 5 6 bin (number) oct (number) hex (number) len (x) chr (x) ord (x)
常用模块和库 os 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 import osos.getcwd() os.listdir() os.remove() os.path.isfile() os.path.isdir() os.path.exists() os.path.dirname() os.path.abspath() os.path.basename() os.system() os.rename(old,new) os.removedirs() os.makedirs() os.mkdir()
time 1 2 3 4 5 6 7 8 9 10 import timetime.time() time.localtime() time.gmtime() time.mktime() time.sleep(n) time.strftime("%Y-%m-%d %H:%M:%S" ) time.strptime()
datetime 1 2 3 4 5 6 7 8 9 import datetimedatetime.date datetime.time datetime.datetime datetime.timedelta datetime.tzinfo datetime.datetime.now() datetime.date.fromtimestamp()
random 1 2 random.choices(demo, k=n) random.sample(demo, n)
turtle 1 2 turtle.seth() turtle.tracer(False )
jieba 1 2 jieba.cut(str ) jieba.lcut(str )
参考文档:https://www.cnblogs.com/wkfvawl/p/9487165.html
wordcloud 1 2 3 w=wordcloud.WordCloud(font_path="C:\\Windows\\Fonts\\msyh.ttf" ) w.generate(str ) w.to_file("demo.png" )
参考文档:https://www.cnblogs.com/dadazunzhe/p/11215452.html
tkinter 1 2 3 4 5 6 7 8 9 win.geometry('800x500' ) win.geometry('+560+250' ) win.title('富贵论坛自动评论-v0.1' ) Entry.get() Text.get('1.0' ,END) Entry.insert('insert' ,'内容' )
参考文档:
https://blog.csdn.net/qq_46018418/article/details/105927203
https://blog.csdn.net/superfanstoprogram/article/details/83713196
https://www.runoob.com/python/python-gui-tkinter.html
selenium 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 from selenium import wedriverwb = webdriver.Chrome() wb.get('url' ) wb.implicitly_wait(10 ) wb.delete_all_cookies() wb.refresh() c = wb.get_cookies() print (c)for item in cookies: if 'expiry' in cookies: del cookies['expiry' ] browser.add_cookie(item) wb.execute_script("window.scrollTo(0, document.body.scrollHeight);" ) browser.find_element_by_xpath('xpath语法' ).send_keys('内容' ) text = browser.find_element_by_xpath('xpath语法' ).get_attribute('textContent' )
参考文档:
https://zhuanlan.zhihu.com/p/111859925
爬虫笔记 常用模块和方法 1 2 3 4 5 6 7 8 9 10 11 12 import requests import re import timeimport osimport lxml import jsomimport js2pyimport jsonpath from fake_useragent import UserAgent import pymysqlimport hashlibimport moviepy.editor
小细节 1 2 3 切片s[:2 ] randint[1 :100 ] range (10 )