123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- """
- @author: luojunhui
- """
- import json
- import requests
- from applications.decoratorApi import retryOnNone
- class WeixinSpider(object):
- """
- Update account articles
- """
- ip = "8.217.190.241"
- # ip = "47.98.154.124"
- port = "8888"
- @classmethod
- @retryOnNone()
- def search_articles(cls, title):
- """
- search articles in wx
- :return:
- """
- url = "http://{}:{}/crawler/wei_xin/keyword".format(cls.ip, cls.port)
- payload = json.dumps({
- "keyword": title,
- "cursor": "1"
- })
- headers = {
- 'Content-Type': 'application/json'
- }
- response = requests.request("POST", url, headers=headers, data=payload)
- return response.json()
- @classmethod
- @retryOnNone()
- def get_article_text(cls, content_link):
- """
- 获取文章
- :param content_link:
- :return:
- """
- url = "http://{}:{}/crawler/wei_xin/detail".format(cls.ip, cls.port)
- payload = json.dumps({
- "content_link": content_link,
- "is_count": False,
- "is_ad": False
- })
- headers = {
- 'Content-Type': 'application/json'
- }
- response = requests.request("POST", url, headers=headers, data=payload)
- return response.json()
- @classmethod
- @retryOnNone()
- def update_msg_list(cls, ghId, index):
- """
- :return:
- """
- url = 'http://{}:{}/crawler/wei_xin/blogger'.format(cls.ip, cls.port)
- payload = {
- 'account_id': ghId,
- 'cursor': index,
- }
- headers = {
- 'Content-Type': 'application/json'
- }
- response = requests.post(url, headers=headers, data=json.dumps(payload), timeout=120)
- # print("response", response.text)
- return response.json()
- @classmethod
- @retryOnNone()
- def get_account_by_url(cls, content_url):
- """
- 通过文章获取账号信息
- :param content_url:
- :return:
- """
- response = requests.request(
- "POST",
- url='http://{}:{}/crawler/wei_xin/account_info'.format(cls.ip, cls.port),
- headers={'Content-Type': 'application/json'},
- json={"content_link": content_url}
- )
- return response.json()
|