亚洲国产精品无码久久大片,亚洲AV无码乱码麻豆精品国产,亚洲品质自拍网站,少妇伦子伦精品无码STYLES,国产精久久久久久久

querylist采集微信公眾號文章(python采集微信公眾號文章本文(操作postgres數據庫)抓取)

優(yōu)采云 發(fā)布時(shí)間: 2022-03-11 17:00

  querylist采集微信公眾號文章(python采集微信公眾號文章本文(操作postgres數據庫)抓取)

  Python搶購搜狗微信公眾號文章

  初學(xué)python,搶搜狗微信公眾號文章存入mysql

  mysql表:

  

  

  代碼:

  

import requests

import json

import re

import pymysql

# 創(chuàng )建連接

conn = pymysql.connect(host='你的數據庫地址', port=端口, user='用戶(hù)名', passwd='密碼', db='數據庫名稱(chēng)', charset='utf8')

# 創(chuàng )建游標

cursor = conn.cursor()

cursor.execute("select * from hd_gzh")

effect_row = cursor.fetchall()

from bs4 import BeautifulSoup

socket.setdefaulttimeout(60)

count = 1

headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:65.0) Gecko/20100101 Firefox/65.0'}

#阿布云ip代理暫時(shí)不用

# proxyHost = "http-cla.abuyun.com"

# proxyPort = "9030"

# # 代理隧道驗證信息

# proxyUser = "H56761606429T7UC"

# proxyPass = "9168EB00C4167176"

# proxyMeta = "http://%(user)s:%(pass)s@%(host)s:%(port)s" % {

# "host" : proxyHost,

# "port" : proxyPort,

# "user" : proxyUser,

# "pass" : proxyPass,

# }

# proxies = {

# "http" : proxyMeta,

# "https" : proxyMeta,

# }

#查看是否已存在數據

def checkData(name):

sql = "select * from gzh_article where title = '%s'"

data = (name,)

count = cursor.execute(sql % data)

conn.commit()

if(count!=0):

return False

else:

return True

#插入數據

def insertData(title,picture,author,content):

sql = "insert into gzh_article (title,picture,author,content) values ('%s', '%s','%s', '%s')"

data = (title,picture,author,content)

cursor.execute(sql % data)

conn.commit()

print("插入一條數據")

return

for row in effect_row:

newsurl = 'https://weixin.sogou.com/weixin?type=1&s_from=input&query=' + row[1] + '&ie=utf8&_sug_=n&_sug_type_='

res = requests.get(newsurl,headers=headers)

res.encoding = 'utf-8'

soup = BeautifulSoup(res.text,'html.parser')

url = 'https://weixin.sogou.com' + soup.select('.tit a')[0]['href']

res2 = requests.get(url,headers=headers)

res2.encoding = 'utf-8'

soup2 = BeautifulSoup(res2.text,'html.parser')

pattern = re.compile(r"url \+= '(.*?)';", re.MULTILINE | re.DOTALL)

script = soup2.find("script")

url2 = pattern.search(script.text).group(1)

res3 = requests.get(url2,headers=headers)

res3.encoding = 'utf-8'

soup3 = BeautifulSoup(res3.text,'html.parser')

print()

pattern2 = re.compile(r"var msgList = (.*?);$", re.MULTILINE | re.DOTALL)

script2 = soup3.find("script", text=pattern2)

s2 = json.loads(pattern2.search(script2.text).group(1))

#等待10s

time.sleep(10)

for news in s2["list"]:

articleurl = "https://mp.weixin.qq.com"+news["app_msg_ext_info"]["content_url"]

articleurl = articleurl.replace('&','&')

res4 = requests.get(articleurl,headers=headers)

res4.encoding = 'utf-8'

soup4 = BeautifulSoup(res4.text,'html.parser')

if(checkData(news["app_msg_ext_info"]["title"])):

insertData(news["app_msg_ext_info"]["title"],news["app_msg_ext_info"]["cover"],news["app_msg_ext_info"]["author"],pymysql.escape_string(str(soup4)))

count += 1

#等待5s

time.sleep(10)

for news2 in news["app_msg_ext_info"]["multi_app_msg_item_list"]:

articleurl2 = "https://mp.weixin.qq.com"+news2["content_url"]

articleurl2 = articleurl2.replace('&','&')

res5 = requests.get(articleurl2,headers=headers)

res5.encoding = 'utf-8'

soup5 = BeautifulSoup(res5.text,'html.parser')

if(checkData(news2["title"])):

insertData(news2["title"],news2["cover"],news2["author"],pymysql.escape_string(str(soup5)))

count += 1

#等待10s

time.sleep(10)

cursor.close()

conn.close()

print("操作完成")

  以上就是本文的全部?jì)热?,希望對大家的學(xué)習有所幫助,也希望大家多多支持。

  時(shí)間:2019-03-31

  python采集微信公眾號文章

  

  本文示例分享了python采集微信公眾號文章的具體代碼,供大家參考。具體內容如下。python的一個(gè)子目錄下存放了兩個(gè)文件,分別是:采集公眾號文章.py和config.py。代碼如下:1.采集公眾號文章.py from urllib.parse import urlencode import pymongo import requests from lxml.etree import XMLSyntaxError from requests.exceptions import Connec

  Python如何爬取微信公眾號文章及評論(基于Fiddler抓包分析)

  

  背景描述我覺(jué)得微信公眾號是比較難爬的平臺之一,但是經(jīng)過(guò)一番折騰,還是有一點(diǎn)小收獲。沒(méi)用Scrapy(估計爬太快有防爬限制),不過(guò)后面會(huì )開(kāi)始整理寫(xiě)一些實(shí)戰。. 簡(jiǎn)單介紹一下本次的開(kāi)發(fā)環(huán)境:python3請求psycopg2(操作postgres數據庫) 抓包分析 本次實(shí)戰對要抓包的公眾號沒(méi)有限制,但是每次抓包前都要對不同的公眾號進(jìn)行分析。打開(kāi)Fiddler,在手機上配置相關(guān)代理。為了避免過(guò)多干擾,這里給Fiddler一個(gè)過(guò)濾規則,指定微信域名即可:

  python爬取微信公眾號文章的方法

  

  最近在學(xué)習Python3網(wǎng)絡(luò )爬蟲(chóng)(崔慶才寫(xiě)的)的開(kāi)發(fā)實(shí)踐,剛剛得知他在這里使用代理爬取了公眾號文章,但是根據他的代碼,還是出現了一些問(wèn)題。我在這里用過(guò)這本書(shū)。對本書(shū)前面提到的一些內容進(jìn)行了改進(jìn)。(作者半年前寫(xiě)了這段代碼,騰訊的網(wǎng)站半年前更新了)我直接加下面代碼:TIMEOUT = 20 from requests import Request, Session, PreparedRequest import requests from selenium import webdrive

  50行Python代碼如何獲取所有公眾號文章

  

  前言我們在閱讀公眾號文章時(shí)通常會(huì )遇到一個(gè)問(wèn)題——閱讀歷史文章的體驗并不好。我們知道爬取公眾號的常用方法有兩種:通過(guò)搜狗搜索獲取,缺點(diǎn)是只能獲取最新的十推文章。通過(guò)微信公眾號的素材管理,可以獲得公眾號文章。缺點(diǎn)是需要自己申請公眾號。微信方式獲取公眾號文章的方法。與其他方法相比,非常方便。如上圖,通過(guò)抓包工具獲取微信的網(wǎng)絡(luò )信息請求,我們發(fā)現每次文章

  Python爬取指定微信公眾號文章

  本文示例分享了python爬取微信公眾號文章的具體代碼,供大家參考。具體內容如下。該方法是依靠 urllib2 庫完成的。首先需要安裝你的python環(huán)境,然后安裝urllib2庫程序的啟動(dòng)方法(返回值為公眾號文章的列表): def openUrl(): print("啟動(dòng)爬蟲(chóng),打開(kāi)搜狗搜索微信界面") # 加載頁(yè)面url = ';s_from=input&query = 被抓取的公眾號名稱(chēng)

  Python爬取微信公眾號文章

  本文示例分享python爬取微信公眾號文章的具體代碼供大家參考,具體內容如下# -*- coding: utf-8 -*- import requests from bs4 import BeautifulSoup from requests .exceptions import RequestException import time import random import MySQLdb import threading import socket import math soc

  python selenium爬取微信公眾號文章代碼詳解

  參考:selenium webdriver 添加cookies: 需求:想看微信公眾號文章的歷史,但是每次都找地方不方便。思路:1.使用selenium打開(kāi)微信公眾號歷史文章,滾動(dòng)刷新到底部,獲取所有歷史文章url。2.遍歷訪(fǎng)問(wèn)url,下載到本地。實(shí)現1.打開(kāi)微信客戶(hù)端,點(diǎn)擊微信公眾號->進(jìn)入公眾號->打開(kāi)歷史文章鏈接(用瀏覽器打開(kāi)),通過(guò)開(kāi)發(fā)者工具獲取cookie

  Python使用webdriver爬取微信公眾號

  本文示例分享了python使用webdriver爬取微信公眾號的具體代碼,供大家參考。具體內容如下# -*- 編碼:utf-8 -*- from selenium import webdriver import time import json import requests import re import random #微信公眾號user="" #公眾號密碼password="" #設置需要爬取的公眾號列表 gzlist=['香河微服務(wù)

  python如何導出微信公眾號文章詳解

  1.安裝wkhtmltopdf 下載地址:我用windows進(jìn)行測試,下載安裝后結果如下 2 編寫(xiě)python代碼導出微信公眾號文章 不能直接使用wkhtmltopdf導出微信公眾號文章,導出的文章會(huì )缺圖,所以需要使用微信公眾號文章頁(yè)面,然后將html文本轉換成pdf pip install wechatsogou --升級 pip install pdfkit 踩坑

  Python抓取微信公眾號賬號信息的方法

  搜狗微信搜索提供了兩種關(guān)鍵詞搜索,一種是搜索公眾號文章的內容,另一種是直接搜索微信公眾號。公眾號基本信息可通過(guò)微信公眾號搜索獲取。還有最近發(fā)布的10個(gè)文章,今天就來(lái)?yè)屛⑿殴娞柕馁~號信息爬蟲(chóng)吧。首先通過(guò)首頁(yè)進(jìn)入,可以按類(lèi)別抓取,通過(guò)“查看更多”可以找到頁(yè)面鏈接規則: import requests as req import re reTypes = r'id="pc_\d*" uigs=" (pc_\d*)">([\s\S]*?)&

  Python爬蟲(chóng)_微信公眾號推送信息爬取示例

  

  問(wèn)題描述 使用搜狗的微信搜索,從指定公眾號抓取最新推送,并將對應網(wǎng)頁(yè)保存到本地。注意,搜狗微信獲取的地址是臨時(shí)鏈接,具有時(shí)效性。公眾號為動(dòng)態(tài)網(wǎng)頁(yè)(JavaScript渲染),使用requests.get()獲取的內容不收錄推送消息。這里使用 selenium+PhantomJS 處理代碼#!/usr/bin/env python3 from selenium import webdriver from datetime import datetime import bs4, requ

0 個(gè)評論

要回復文章請先登錄注冊


官方客服QQ群

微信人工客服

QQ人工客服


線(xiàn)

亚洲国产精品无码久久大片,亚洲AV无码乱码麻豆精品国产,亚洲品质自拍网站,少妇伦子伦精品无码STYLES,国产精久久久久久久