python
zoey要早起
这个作者很懒,什么都没留下…
展开
-
【Python】json
json.dumps将 Python 对象编码成 JSON 字符串json.loads将已编码的 JSON 字符串解码为 Python 对象import json import pytest#将string转换成dict#见到 : 和 , 就自动转换成dictdef test_loads(): s = '{"k1": "v1"}' # 注意:由于是字符串,所以有'' loads_sth = json.loads(s) assert type(loads_sth)原创 2021-03-08 09:35:42 · 61 阅读 · 0 评论 -
【Python】爬取子域名
利用站长之家的子域名查询工具import jsonimport requestsfrom lxml import etreeurl = "http://tool.chinaz.com/subdomain/zoom.us" #修改最后headers = { "Host": "tool.chinaz.com", "Upgrade-Insecure-Requests": "1", "User-Agent": "Mozilla/5.0 (X11; Linux x86_64) Ap原创 2021-02-04 13:30:02 · 638 阅读 · 1 评论 -
【Python】遇到的问题及解决方法
python爬虫遇到requests.exceptions.ConnectionError: HTTPSConnectionPool(host=…port=443)解决方法原创 2021-02-03 10:44:39 · 85 阅读 · 0 评论 -
【Python】requests
socat TCP-LISTEN:7788,fork TCP:192.168.0.14:9000Python requests我们可以检测响应状态码:r = requests.get('http://httpbin.org/get')r.status_code为方便引用,Requests还附带了一个内置的状态码查询对象:r = requests.get('http://httpbin.org/get')print r.status_code == requests.codes.ok如原创 2021-01-30 11:35:46 · 112 阅读 · 0 评论 -
【Python】popen
popen通过read方法读取p = os.popen("ping "+ host + " -w 10") # ping只读20行line = p.read()原创 2021-01-25 09:57:31 · 61 阅读 · 0 评论 -
【Python】pytest
assert断言用于判断实际结果和期望结果,符合预期就pass,不符合就failed。在自动化测试中,一个用例里必须要有断言。运行一个测试test_simple.pyimport pytestdef func(x): return x + 1def test_answer(): assert func(3) == 5 #assert断言if __name__ == '__mian__': pytest.main()测试➜ pytest test_simple.p原创 2021-01-19 10:36:26 · 128 阅读 · 0 评论