#本文仅供学习之用
由于获取的响应内容不是JSON数据也不是静态页面只能通过lxmlxpath完成注意格式
import requests
cookies = {
'_uq': '41047ede63ba9fa098e72e449062fe93',
'uniqid': 'd01o8vk4trqm6',
'_suq': '14ee7588-acad-4654-8b05-5be72cb5d6ac',
'Hm_lvt_a360b5a82a7c884376730fbdb8f73be2': '1721341370',
'HMACCOUNT': '70E52AFDD5606235',
'unionJsonOcpc': 'e30=',
'vidSended': '1',
'zbj_pubHistory': '{%22type%22:%22search%22%2C%22value%22:%22saas%22}',
'Hm_lvt_c189d409e2c6b8c7bf93dc6ba2a49c79': '1721341488',
'localCityInfo': '{%22handleInfo%22:{%22cityId%22:3584%2C%22cityName%22:%22%E5%BC%A0%E5%AE%B6%E5%8F%A3%22%2C%22cityEname%22:%22zjk%22%2C%22provinceId%22:3569%2C%22provinceName%22:%22%E6%B2%B3%E5%8C%97%22%2C%22adminCode%22:%22130700%22%2C%22towns%22:%22%22}%2C%22localInfo%22:{%22cityId%22:3584%2C%22cityName%22:%22%E5%BC%A0%E5%AE%B6%E5%8F%A3%22%2C%22cityEname%22:%22zjk%22%2C%22provinceId%22:3569%2C%22provinceName%22:%22%E6%B2%B3%E5%8C%97%22%2C%22adminCode%22:%22130700%22}}',
}
headers = {
'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
'accept-language': 'zh-CN,zh;q=0.9',
'cache-control': 'max-age=0',
'priority': 'u=0, i',
'referer': 'https://www.zbj.com/',
'sec-ch-ua': '"Not/A)Brand";v="8", "Chromium";v="126", "Google Chrome";v="126"',
'sec-ch-ua-mobile': '?1',
'sec-ch-ua-platform': '"Android"',
'sec-fetch-dest': 'document',
'sec-fetch-mode': 'navigate',
'sec-fetch-site': 'same-origin',
'sec-fetch-user': '?1',
'upgrade-insecure-requests': '1',
'user-agent': 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Mobile Safari/537.36',
}
params = {
'k': 'saas',
}
response = requests.get('https://m.zbj.com/fw/', params=params, cookies=cookies, headers=headers)
print(response.text)
#调用LXML模块
from lxml import etree
html=etree.HTML(response.text)
divs = html.xpath("//div[@class='m-service-box']")
#标签加属性用[]用@对于img直接@就可以注意父子关系带参数
for item in divs:
name= item.xpath("./div/div[@class='m-service-card']/a/div[@class='service-info-text']/div[@class='service-name-box']/span[@class='service-name']/text()")[0]
price=item.xpath("./div/div[@class='m-service-card']/a/div[@class='service-info-text']/div[@class='service-price']/div[@class='discount-price']/span[@class='price-text']/text()")[0]
print(name,price)
用lxml中的etree对猪八戒服务名称价格获取
于 2024-07-19 21:53:49 首次发布
2226

被折叠的 条评论
为什么被折叠?



