使用pyquery爬取搜狗微信文章
2019-04-08 11:16
127 查看
版权声明:转载需注明来源 https://blog.csdn.net/weixin_44024393/article/details/89084309
缺点:还是没有使用代理,出现验证码就停止抓取了
import requests from pyquery import PyQuery as pq from fake_useragent import UserAgent from urllib.parse import urlencode import queue import re # 构建请求头 ua = UserAgent() headers = { 'user-agent': ua.Chrome, 'cookie': '自己设置' } # 声明一个列表存储字典 data_list = [] def get_index(q): url = q.get() # 请求url resp = requests.get(url, headers=headers) # 将返回的数据转成pyquery格式 doc = pq(resp.content) # 分析网页,抓取ul标签下的li标签,这里使用的是items # 因为抓取到的是多个节点对象,所以需要使用items方法将其转成list # 方可对其进行遍历 lis = doc('.news-list li').items() # 遍历li标签,抓取所需的数据 for li in lis: # 文章题目 title = li.find('h3').text() # 作者 author = li.find('.s-p a').text() # 摘要 content = li.find('p').text() # 时间戳,爬到的数据document.write(timeConvert('1526012173')) datetime = li.find('.s2 script').text() # 使用正则匹配时间戳 datetime = re.findall(r'\d+', datetime)[0] # 声明一个字典存储数据 data_dict = {} data_dict['title'] = title data_dict['author'] = author data_dict['content'] = content data_dict['datetime'] = datetime data_list.append(data_dict) def main(): # 声明一个队列存储url q = queue.Queue() for page in range(1, 10): # 构建url参数 data = { 'query': 'python爬虫', 'type': '2', 'page': page } # 将url的参数进行编码后拼接到url url = 'https://weixin.sogou.com/weixin?' + urlencode(data) # 将url存入队列中 q.put(url) # 当列表不为空,则继续爬取 while not q.empty(): get_index(q) if __name__ == '__main__': main() print(data_list)
相关文章推荐
- 【学习】06 爬虫使用代理地址爬取搜狗微信文章
- 使用selenium爬取搜狗微信文章
- requests;exceptions;UA;pq;re;time爬取搜狗微信文章(使用代理池,免费自造的代理池)
- 使用QueryList解析微信文章
- nodejs爬虫-通过抓取搜狗微信网站获取微信文章信息
- nodejs爬虫抓取搜狗微信文章详解
- python爬虫实战(三)--------搜狗微信文章(IP代理池和用户代理池设定----scrapy)
- 采集微信公众号文章只需几步(非搜狗微信)
- python3爬虫用代理池爬虫搜狗微信文章
- 搜狗微信搜索2.0公测 微信精品文章分享可上头条噢
- 使用webmagic爬取搜狗上公众账号发布的文章信息
- 如何使用Wordpress搭建微信小程序(一)获取分页文章api
- 微信编辑器中使用ueditor,百度ueditor编辑器发送公众号文章
- 爬虫知识点---微信搜狗---xpath--pyquery--csselect--正则--bs4
- python爬虫实战--------搜狗微信文章(IP代理池和用户代理池设定----scrapy)
- 在Web微信应用中使用博客园RSS以及Quartz.NET实现博客文章内容的定期推送功能
- 微信小程序例子——使用画布组件绘制一个长200px,宽100px的长方形
- python使用itchat库实现微信机器人
- 如何使用live writer客户端来发布CSDN的博客文章?
- VeeValidate 使用笔记(此文章使用环境VUE+webpack)