requests

requests模块爬虫使用

今天使用requests,爬取"http://langlang2017.com/
立马上代码!

#第一步使用代理
#都是键值对,而且有HTTP 和HTTPS的代理
import requests

proxy={
    "HTTP": "113.3.152.88:8118",
    "HTTPS":"219.234.5.128:3128",
}

#伪装请求头
headers={
         "User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko)Chrome/70.0.3538.110 Safari/537.36",
    }
    
#第一种发起请求 使用get方式 网址 代理
response=requests.request("get","http://langlang2017.com/",proxies=proxy,headers=headers)
# 返回状态码
print(response)

# 返回字节流内容 解码为utf-8
print(response.content.decode("utf-8"))
# 返回返回文本内容
print(response.text)
#第二种发起请求
response1=requests.get("http://langlang2017.com/",headers=headers,proxies=proxy)
print(response1)# 返回状态码

# 返回字节流内容 解码为utf-8
print(response1.content.decode("utf-8"))
# 返回返回文本内容
print(response1.text)




爬虫其实很简单,难的是应对反爬机制!要灵活应对!更新完所有基础就,就开始反反爬虫!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值