使用requests+pyquery爬取dd373地下城跨五最新商品信息
废话不多说直接上代码:
可以使用openpyel库对爬取的信息写入Execl表格中代码我就不上传了
import requests
from urllib.parse import urlencode
from requests import RequestException
from pyquery import PyQuery as pq def open_sh():
#获取dd373html信息
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36'
}
data = {
"minPrice":333,
"maxPrice":""
}
url = "https://www.dd373.com/s/rbg22w-x9kjbs-wwf11b-0-0-0-qquvn4-0-0-0-0-0-0-0-0.html?"+urlencode(data)
try:
response = requests.get(url,headers=headers)
if response.status_code == 200:
return response.text
return None
except RequestException:
print("链接错误",url)
return None def doc_page(html):
# 获取地下城账号信息
doc = pq(html)
content = doc("div.content")
titleText = content.find(".box.money_ner").items()
for items in titleText:
product = {
"地址":items.find("a.titleText").attr("href"),
"账号信息":items.find("a.titleText").text(),
"价格":items.find("div.money_text strong span").text()+'元',
"是否存在":items.find("div.num.left").text()
}
print(product)
def page_sh(pagebox):
# 循环遍历所有分页
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36'
}
data = {
"minPrice": 333,
"maxPrice": ""
}
for page in range(1,pagebox+1):
url = "https://www.dd373.com/s/rbg22w-x9kjbs-wwf11b-0-0-0-qquvn4-0-0-0-0-0-0-0-%s.html?%s"%(page,urlencode(data))
try:
page1 = page_currentpage(url)
if page1==page:
response = requests.get(url, headers=headers)
if response.status_code == 200:
doc_page(response.text)
except Exception as e:
raise e def page_currentpage(html):
# 获取分页中被高亮的页数用于判断是否在 当前页面
doc = pq(html)
currentpage= doc("a.nb.currentpage").text()
return int(currentpage) def page_box(html):
# 获取所有的页码
doc = pq(html)
pagebox = doc(".pagebox.clear ul li.yeshu").text()[9:-1]
return int(pagebox) def main():
html = open_sh()
page = page_box(html)
page_sh(page) if __name__ == "__main__":
main()
使用requests+pyquery爬取dd373地下城跨五最新商品信息的更多相关文章
- 利用Python爬虫爬取指定天猫店铺全店商品信息
本编博客是关于爬取天猫店铺中指定店铺的所有商品基础信息的爬虫,爬虫运行只需要输入相应店铺的域名名称即可,信息将以csv表格的形式保存,可以单店爬取也可以增加一个循环进行同时爬取. 源码展示 首先还是完 ...
- [实战演练]python3使用requests模块爬取页面内容
本文摘要: 1.安装pip 2.安装requests模块 3.安装beautifulsoup4 4.requests模块浅析 + 发送请求 + 传递URL参数 + 响应内容 + 获取网页编码 + 获取 ...
- requests+正则爬取豆瓣图书
#requests+正则爬取豆瓣图书 import requests import re def get_html(url): headers = {'User-Agent':'Mozilla/5.0 ...
- requests+正则表达式爬取ip
#requests+正则表达式爬取ip #findall方法,如果表达式中包含有子组,则会把子组单独返回出来,如果有多个子组,则会组合成元祖 import requests import re def ...
- 一起学爬虫——使用selenium和pyquery爬取京东商品列表
layout: article title: 一起学爬虫--使用selenium和pyquery爬取京东商品列表 mathjax: true --- 今天一起学起使用selenium和pyquery爬 ...
- 爬虫系列4:Requests+Xpath 爬取动态数据
爬虫系列4:Requests+Xpath 爬取动态数据 [抓取]:参考前文 爬虫系列1:https://www.cnblogs.com/yizhiamumu/p/9451093.html [分页]:参 ...
- 爬虫系列2:Requests+Xpath 爬取租房网站信息
Requests+Xpath 爬取租房网站信息 [抓取]:参考前文 爬虫系列1:https://www.cnblogs.com/yizhiamumu/p/9451093.html [分页]:参考前文 ...
- 爬虫系列1:Requests+Xpath 爬取豆瓣电影TOP
爬虫1:Requests+Xpath 爬取豆瓣电影TOP [抓取]:参考前文 爬虫系列1:https://www.cnblogs.com/yizhiamumu/p/9451093.html [分页]: ...
- PYTHON 爬虫笔记八:利用Requests+正则表达式爬取猫眼电影top100(实战项目一)
利用Requests+正则表达式爬取猫眼电影top100 目标站点分析 流程框架 爬虫实战 使用requests库获取top100首页: import requests def get_one_pag ...
随机推荐
- 前端知识之jQuery
通过 jQuery,您可以选取(查询,query) HTML 元素,并对它们执行"操作"(actions). http://www.runoob.com/jquery/jquery ...
- 20165223《网络对抗技术》Exp0 Kali的安装
(1)安装步骤 Kali官网,下载Kali Linux 64 bit版本,按照网上安装教程进行即可 我是直接拷贝了Kali的.vmx文件(Linux 64bit),在上学期已经安装好的VMware中可 ...
- Redis主从配置和哨兵监控配置——服务器端环境搭建
一:介绍 公司用到的redis框架,主要分为cluster的缓存集群和sentinel中的哨兵主从.这种的选用方式一般需要更具业务场景来做区分,两种框架的配置图为:右图为哨兵主从框架和cliuster ...
- Glog使用记录
1.Flag_xxx FLAGS_logtostderr = false; //是否将所有日志输出到stderr,而非文件 FLAGS_alsologtostderr = false; //日志记录到 ...
- C# webapi 上传下载图片
客户端上传文件 string url = url + "webUploadFile"; Uri server = new Uri(url); HttpClient httpClie ...
- 分布式协调服务Zookeeper集群搭建
分布式协调服务Zookeeper集群搭建 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.安装jdk环境 1>.操作环境 [root@node101.yinzhengjie ...
- Tomcat系列(10)——Tomcat主要设计模式5种(外观,责任链,观察者,模板方法,命令模式)
核心部分 外观模式: RequestFacade应用门面模式(facade)来封装HttpServletRequest. 观察者模式: 事件监听机制,控制组件生命周期的 Lifecycle .Serv ...
- postgreSql 基本操作总结
0. 启动pgsl数据库 pg_ctl -D /xx/pgdata start 1. 命令行登录数据库 1 psql -U username -d dbname -h hostip -p po ...
- 代理模式-JDK Proxy(Java实现)
代理模式-JDK Proxy 使用JDK支持的代理模式, 动态代理 场景如下: 本文例子代理了ArrayList, 在ArrayList每次操作时, 在操作之前和之后都进行一些额外的操作. Array ...
- DirectX11 With Windows SDK--26 计算着色器:入门
前言 现在开始迎来所谓的高级篇了,目前计划是计算着色器部分的内容视项目情况,大概会分3-5章来讲述. DirectX11 With Windows SDK完整目录 Github项目源码 欢迎加入QQ群 ...