Skip to content

Commit

Permalink
Upload a new passage.
Browse files Browse the repository at this point in the history
  • Loading branch information
StandardL committed Jul 23, 2023
1 parent b83b78c commit d3e758f
Show file tree
Hide file tree
Showing 2 changed files with 414 additions and 0 deletions.
27 changes: 27 additions & 0 deletions _posts/2023-07-03-Python爬虫0.5---各个模块的介绍.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,19 @@ r.content # 以字节的方式返回内容,比如用于下载图片
r.cookies # 写入的本地cookies数据
```

补充:requests请求时附带cookie字典

```python
import requests
cookie = {
"BAIDUID_BFESS" : "4051D8C947D33A9ED35222FECFF4AEB9:FG=1"
}
r = requests.get(
"http://url",
cookies = cookie
)
```

更多关于requests的内容,请访问:[菜鸟教程 - requests](https://www.runoob.com/python3/python-requests.html)[Pypi](https://pypi.org/project/requests/)

---
Expand Down Expand Up @@ -145,3 +158,17 @@ node.nmae # 获取查找到的节点的标签名
node['href'] # 获取找到的节点的href属性
node.get_text() # 获取找到的节点的链接文字
```

---

## Python使用正则表达式实现模糊匹配

```python
import re
pattern = r'^https://standardl.github.io/posts/\S+$'

print(re.match(pattern, url))
# 当匹配成功时,其返回一个一赔的对象;否则返回None
```

更多关于Python正则表达式,请访问:[菜鸟教程 - Python正则表达式](https://www.runoob.com/python/python-reg-expressions.html),重点关注正则表达式模式部分。
Loading

0 comments on commit d3e758f

Please sign in to comment.