Python爬虫学习
2022/5/30 1:19:50
本文主要是介绍Python爬虫学习,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
一、
爬虫:代码模拟浏览器向服务器发送请求并得到目标数据。
二、
1.get请求
1 import requests 2 3 query = input("请输入你想查询的内容:") 4 url = f"https://www.sogou.com/web?query={query}" 5 6 header = { 7 "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3100.0 Safari/537.36" 8 } 9 10 res = requests.get(url, headers=header) 11 12 print(res) 13 print(res.request) 14 print(res.encoding) 15 16 with open('sougou.html', mode="w", encoding='utf-8') as f: 17 f.write(res.text) 18 f.close()
2.post请求
import requests url = "https://fanyi.baidu.com/sug" s = input('请输入您想查询的单词:') da = { 'kw': s } res = requests.post(url, data=da) res.close() res = res.json() print(res['data'][0]['k']+'的中文翻译为为:') print(res['data'][0]['v'])
这篇关于Python爬虫学习的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-05-08有遇到过吗?同样的规则 Excel 中 比Python 结果大
- 2024-03-30开始python成长之路
- 2024-03-29python optparse
- 2024-03-29python map 函数
- 2024-03-20invalid format specifier python
- 2024-03-18pool.map python
- 2024-03-18threads in python
- 2024-03-14python Ai 应用开发基础训练,字符串,字典,文件
- 2024-03-13id3 algorithm python
- 2024-03-13sum array elements python