废话不多说直接上代码:

  可以使用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地下城跨五最新商品信息的更多相关文章

  1. 利用Python爬虫爬取指定天猫店铺全店商品信息

    本编博客是关于爬取天猫店铺中指定店铺的所有商品基础信息的爬虫,爬虫运行只需要输入相应店铺的域名名称即可,信息将以csv表格的形式保存,可以单店爬取也可以增加一个循环进行同时爬取. 源码展示 首先还是完 ...

  2. [实战演练]python3使用requests模块爬取页面内容

    本文摘要: 1.安装pip 2.安装requests模块 3.安装beautifulsoup4 4.requests模块浅析 + 发送请求 + 传递URL参数 + 响应内容 + 获取网页编码 + 获取 ...

  3. requests+正则爬取豆瓣图书

    #requests+正则爬取豆瓣图书 import requests import re def get_html(url): headers = {'User-Agent':'Mozilla/5.0 ...

  4. requests+正则表达式爬取ip

    #requests+正则表达式爬取ip #findall方法,如果表达式中包含有子组,则会把子组单独返回出来,如果有多个子组,则会组合成元祖 import requests import re def ...

  5. 一起学爬虫——使用selenium和pyquery爬取京东商品列表

    layout: article title: 一起学爬虫--使用selenium和pyquery爬取京东商品列表 mathjax: true --- 今天一起学起使用selenium和pyquery爬 ...

  6. 爬虫系列4:Requests+Xpath 爬取动态数据

    爬虫系列4:Requests+Xpath 爬取动态数据 [抓取]:参考前文 爬虫系列1:https://www.cnblogs.com/yizhiamumu/p/9451093.html [分页]:参 ...

  7. 爬虫系列2:Requests+Xpath 爬取租房网站信息

    Requests+Xpath 爬取租房网站信息 [抓取]:参考前文 爬虫系列1:https://www.cnblogs.com/yizhiamumu/p/9451093.html [分页]:参考前文 ...

  8. 爬虫系列1:Requests+Xpath 爬取豆瓣电影TOP

    爬虫1:Requests+Xpath 爬取豆瓣电影TOP [抓取]:参考前文 爬虫系列1:https://www.cnblogs.com/yizhiamumu/p/9451093.html [分页]: ...

  9. PYTHON 爬虫笔记八:利用Requests+正则表达式爬取猫眼电影top100(实战项目一)

    利用Requests+正则表达式爬取猫眼电影top100 目标站点分析 流程框架 爬虫实战 使用requests库获取top100首页: import requests def get_one_pag ...

随机推荐

  1. IIS7.0 asp不能连接access数据 静态系统后台列表不显示 的问题

    首先看一下系统磁盘的格式,看是NTFS的还是FAT32的,如果是NTFS的一般就是权限的问题,因为iis读取数据库在系统盘是有缓存的,所以对权限有要求,找到系统盘缓存目录: C:/Windows/te ...

  2. 1.openshift

    openshit是红帽开源的容器云平台.

  3. JavaScript判断是否为微信浏览器或支付宝浏览器

    可以用手机安装的微信和支付宝扫描下方二维码测试 <!DOCTYPE html> <html lang="en"> <head> <meta ...

  4. [ffmpeg] 滤波格式协商

    ffmpeg的中滤波器是以帧为原料来进行滤波的,那么自然地就会对帧的格式有所要求,可以说如果滤波器不知道帧的格式,就无法对帧进行处理.在进行视频滤波时,滤波格式指的是视频的像素格式:在进行音频滤波时, ...

  5. 轻松理解 Spark 的 aggregate 方法

    2019-04-20 关键字: Spark 的 agrregate 作用.Scala 的 aggregate 是什么 Spark 编程中的 aggregate 方法还是比较常用的.本篇文章站在初学者的 ...

  6. 一本通网站 1378:最短路径(shopth)

    [题目描述] 给出一个有向图G=(V, E),和一个源点v0∈V,请写一个程序输出v0和图G中其它顶点的最短路径.只要所有的有向环权值和都是正的,我们就允许图的边有负值.顶点的标号从1到n(n为图G的 ...

  7. 百度编辑器前后端二开图片上传Js Thinkphp tp5 ueditor

    百度编辑器图片上传Jsueditor.all.min.js 下载链接 链接:https://pan.baidu.com/s/1VNgw9ELgRRHKeCQheFkQTw 提取码:fnfi 使用方法: ...

  8. 自定义滚动条样式-transition无效

    问题 需求是自定义滚动条样式,然后2秒内无操作隐藏滚动条. 2s内隐藏比较麻烦,不能用css实现,只能监听容器的touch事件,然后给滚动条加个opacity: 0的class. .class::-w ...

  9. C++: 类成员初始化列表语法

      类的成员初始化列表的初始化的基本语法,类的构造函数还可以运用此语法为其变量初始化: class Class { private: int a; int b; char ch; public: Cl ...

  10. poj 2886 "Who Gets The Most Candies?"(树状数组)

    传送门 参考资料: [1]:http://www.hankcs.com/program/algorithm/poj-2886-who-gets-the-most-candies.html 题意: 抢糖 ...