爬虫1

异常,导包,文件,爬虫,自动化,目录,数据库,框架
爬虫
import html
import requests
import lxml
from lxml import etree
url=“http://www.baidu.cn”
headers={}
cookies={}
referer=""
proxies={“http:http://192.168.10.12:8830”}
//一定要小心headers是否写错了,尤其是里面的空格
#发送请求
response=request.get(url=url,headers=headers,proxies=proxies,referer=refer,pararm=pararm)
#response=requset.post(data,url,headers,cookies,proxies)
#接收请求后的响应
data=response.text
data=response.content
data=response.text.decode(“UTF-8”)
data=response.content.decode(“utf-8”)
#筛选数据
1.正则表达式
2.beautifulsoup4
3.lxml
4.json

html=etree.HTML(data)
list=html.xpath("//img/@href")
print(list)
for i in list:
dict={“img”:i}
print(dict)
#如果是多个列表可以使用zip()函数进行封装,比如zip(list1,list2)

import json
from jsonpath import jsonpath
url=""
referer=""
headers={}#use-agent:
proxies={}
cookies=""

response=requests.get(url,headers,proxies,cookies,referer)
data=response.text.stript(“fectch(”)
information=data.stript("")
json_data=json.loads(information)
img_data=jsonpath("KaTeX parse error: Expected 'EOF', got '#' at position 9: ..img") #̲如果import导入的是jso……path)
img_data=jsopath.jsonpath($…path)
print(img_data)
for i in img_data:
print(i)

以上是今天的爬虫总结,不适合新手观看,如有错误请多多指教,由于今天太晚了,今天的爬虫总结就到这里了,明天继续讲beautifulsoup4和selenium以及appium的自动化爬虫。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值