废话不多说直接上代码:

  可以使用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. IntelliJ IDEA 2018 最新版注册码

    参考:IntelliJ IDEA 2018注册码(无需修改hosts文件) :

  2. C语言博客作业02--循环结构

    1.本章学习总结 1.1 思维导图 1.2 本章学习体会及代码量学习体会 1.2.1 学习体会 经过本周学习,对c循环结构有了深入,无论是单层循环结构还是嵌套循环结构的问题,我都学会有一定的解决能力, ...

  3. CF 543C Remembering Strings

    https://cn.vjudge.net/problem/CodeForces-543C 题目 You have multiset of n strings of the same length, ...

  4. SpringMVC 监听文件上传进度

    Spring MVC 监听文件上传进度 具体实现分三个步骤: 接管CommonsMultipartResolver,重写针对文件上传的请求. 在第一步中写入监听,以获取上传进度. 修改上传部分的配置文 ...

  5. CF1129B 【Wrong Answer】

    既然 $ n \leq 2000$ 那我们就假使所有的 $n = 2000 $ 主要是为了方便.再使 \(x = \sum_{i=1} ^ {1999}\) 以及 $a_1=a_2=a_3=...=a ...

  6. cenos7上部署python3环境以及mysqlconnector2.1.5

    本机的python2不要管他,因为可能有程序依赖目前的python2环境,比如yum!!!!! 一.安装python3依赖环境: yum -y install zlib-devel bzip2-dev ...

  7. 【Unity游戏开发】你真的了解UGUI中的IPointerClickHandler吗?

    一.引子 马三在最近的开发工作中遇到了一个比较有意思的bug:“TableViewCell上面的某些自定义UI组件不能响应点击事件,并且它的父容器TableView也不能响应点击事件,但是TableV ...

  8. python 玩耍天地

    词云 wordcloud wordcloud轮子下载 下载上面链接里对应的 whl (我选的 xxx_win32.whl)到 本地 进行安装 一般地, 会结合 jieba 分词 还有 matplotl ...

  9. SQL SERVER服务器登录名、角色、数据库用户、角色、架构的关系

    原创链接:https://www.cnblogs.com/junfly/articles/2798023.html SQL SERVER 基础教程中关于服务器登录名.服务器角色.数据库用户.数据库角色 ...

  10. Linux动态链接库的生成和使用

    目录 1. 编写C程序 2. 编译动态链接库 3. 使用共享库 4. 执行程序 5. 参考资料 1. 编写C程序 比如编写myfunc.c文件,里面包含两个函数,一个是say_hello,另一个是ca ...