当前位置:网站首页>Some simple uses of crawler requests Library
Some simple uses of crawler requests Library
2022-07-29 07:58:00 【Zhao [email protected]】
requests Use Official documents
1、 and urllib It's the same Is to HTTP Send a request
1、GET request
python
import requests
url ="http://www.baidu.com"
r =requests.get(url=url)
Parameterized GET request , And save
import requests
from fake_useragent import UserAgent
headers ={
"User-Agent":UserAgent().chrome
}
data ={
"kw":" book ",
}
url ="https://tieba.baidu.com/f?"
r =requests.get(url=url,params=data)
#print(r.text)
with open("tieba.html","wb")as fp:
fp.write(r.content)
2、 Custom request header
import requests
from fake_useragent import UserAgent
headers ={
"User-Agent":UserAgent().random
}
url ="http://www.baidu.com"
r =requests.get(url=url,headers=headers)
3、 Response object
r.text View the response as a string
r.content Byte type view response
r.encoding View or set the coding type (utf8 perhaps gbk etc. )
r.status_code Check the status code
r.headers View the response header
r.url View request url
r.json json Response in format
4、POST request
Must translate
import requests
from fake_useragent import UserAgent
headers ={
"User-Agent":UserAgent().chrome
}
formdata ={
"from":"en",
"text":"dog",
"to":"zh - Hans"
}
url = "https://cn.bing.com/tlookupv3?isVertical=1&&IG=E2B1985FC4C04621828E387B864AB30C&IID=translator.5027.2"
r =requests.post(url=url,headers=headers,data=formdata)
print(r.status_code)
5、
6、
7 agent
Cicci agent
import requests
from fake_useragent import UserAgent
headers ={
"User-Agent":UserAgent().chrome
}
proxies ={
"http":"http://60.2.44.182:30963",
}
url ="https://www.baidu.com/s?ie=UTF-8&wd=ip"
r =requests.get(url=url,headers=headers,proxies=proxies)
# print(r.text)
with open("daili.html","wb")as fp:
fp.write(r.content)
8、cookie Session login
import requests
from fake_useragent import UserAgent
headers ={
"User-Agent":UserAgent().chrome
}
# Encounter the problem of conversation , You need to create a session first ,, Then the created session object is saved cookie Information
# All operations below pass s Visit ,s.post s.get
s =requests.Session()
post_url ="http://www.renren.com/ajaxLogin/login?1=1&uniqueTimestamp=202043200369 "
formdata={
"icode":"",
"key_id":"1",
"email":" Own account ",
"rkey":"1675e02911435a4867105858c862a18c",
"password":" password ",
"origURL":"http://www.renren.com/home",
"f":"https%3A%2F%2Fwww.baidu.com%2Flink%3Furl%3DOyMkLmY-DmwEtjONGn3IO2CEVIEZHHjxeeHGy6z3olK%26wd%3D%26eqid%3Dceab788e00072b59000000025ebbe1a2",
"domain":"renren.com",
"captcha_type":"web_login"
}
#
r =s.post(url=post_url,headers=headers,data=formdata)
# print(r.text)
get_url ="http://www.renren.com/974397449/profile"
#s.get I'll take cookie Go to the page after login
r =s.get(get_url,headers=headers)
print(r.text)
版权声明
本文为[Zhao [email protected]]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/210/202207290520358348.html
边栏推荐
- 准备esp32环境
- Autojs微信研究:微信自动发送信息机器人最终成品(有效果演示)
- Detailed explanation of the find command (the most common operation of operation and maintenance at the end of the article)
- Data warehouse modeling, what is wide table? How to design? Advantages and disadvantages
- @JsonSerialize注解的使用
- Solve the problem that the disk is full due to large files
- Convert source package to RPM package
- Measured waveform of boot capacitor short circuit and open circuit of buck circuit
- [paper reading] tomoalign: a novel approach to correcting sample motion and 3D CTF in cryoet
- 《nlp入门+实战:第五章:使用pytorch中的API实现线性回归》
猜你喜欢

@Use of jsonserialize annotation
功能自动化测试实施的原则以及方法有哪些?

MySQL uses date_ FORMAT(date,'%Y-%m')

Autojs微信研究:微信自动发送信息机器人最终成品(有效果演示)
![[cryoEM] Introduction to FSC, Fourier shell correlation](/img/01/6a4f6041444abfd1d3ca7e0c14b524.png)
[cryoEM] Introduction to FSC, Fourier shell correlation

Solve the problem that CSDN cannot publish blog due to unknown copyright

Convert source package to RPM package

Useful websites

Day 014 二维数组练习

Ionicons icon Encyclopedia
随机推荐
What is the use of chat robots? What type? After reading these, you will understand!
[cryoelectron microscope] relion4.0 pipeline command summary (self use)
Amaze UI 图标查询
在一个sql文件中,上面定义一个测试表及数据,下面可以select* from 测试表
flutter只要是数据,都会判空的
Unity beginner 2 - tile making and world interaction (2D)
Dynamic Thresholds Buffer Management in a Shared Buffer Packet Switch论文总结
[cryoelectron microscope | paper reading] interpretation of sub fault average m software: multi particle cryo EM refining with M
Mutationobserver document learning
Multi thread shopping
Jump from mapper interface to mapping file XML in idea
Cs61abc sharing session (VI) detailed explanation of program input and output - standard input and output, file, device, EOF, command line parameters
[note] the art of research - (tell a good story and argument)
[freeze electron microscope] analysis of the source code of the subtomogram alignment function of relion4.0 (for self use)
Implementation of simple matcap+fresnel shader in unity
[cryoelectron microscope | paper reading] emclarity: software for high-resolution cryoelectron tomography and sub fault averaging
Pytorch's skill record
IonIcons图标大全
Character shader exercise
MapReduce steps of each stage