python

蛋蛋 2022年09月13日 23 0

成员运算符

in/not in

查看是否在字典中

dic = {‘a’:1,‘b’:2,‘c’:3,‘d’:4}
print(‘a’ in dic)

True
print(‘a’ not in dic)

False

案例

使用导出为word文案例

使用导出为word文档的方法,但是没有办法指定保存的位置

def download_doc():
    driver.find_element_by_css_selector('[uib-tooltip-diy="导出文档"]').click()
    import_doc = driver.find_element_by_css_selector('[uib-tooltip-diy="导出Word"]')
    print(import_doc)
    import_doc.click()
    time.sleep(55)

档的方法,但是没有办法指定保存的位置

def download_doc():
    driver.find_element_by_css_selector('[uib-tooltip-diy="导出文档"]').click()
    import_doc = driver.find_element_by_css_selector('[uib-tooltip-diy="导出Word"]')
    print(import_doc)
    import_doc.click()
    time.sleep(55)

爬虫

学习网页

如何学习Python爬虫[入门篇] 路人甲
https://zhuanlan.zhihu.com/p/21479334/
python2

怎么用Python写爬虫抓取网页数据
https://www.cnblogs.com/aiandbigdata/p/10087000.html

Python Spider 2020
https://github.com/Jack-Cherish/python-spider/tree/master/2020
python3

爬虫

urllib.request 和 requests

  • urllib库是Python内置的,无需我们额外安装,只要安装了 Python 就可以使用这个库。
  • requests 库是第三方库,需要我们自己安装。
    requests 库强大好用,后续文章的实例,也都是以此为基础进行讲解。requests 库的 github 地址:
    https://github.com/requests/requests

python3与python2

python3中urllib2找不到怎么办

获取
python2写法


python3写法

import urllib.request

def download(url):
    reponse = urllib.request.urlopen(url,timeout=5)
    # urllib.request.Request(url,headers=)
    print(type(reponse))
    print(reponse.info())
download('https://baidu.com')

Python3开启自带http服务

# cd www目录
# python -m http.server
Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/) …

保持服务

nohup python -m http.server 8001
Last Updated: 2023/03/01 10:28:04
markdown使用指南 go