wxSpiderApi.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. """
  2. @author: luojunhui
  3. """
  4. import json
  5. import time
  6. import requests
  7. from applications.decoratorApi import retryOnNone
  8. class WeixinSpider(object):
  9. """
  10. Update account articles
  11. """
  12. @classmethod
  13. @retryOnNone()
  14. def search_articles(cls, title):
  15. """
  16. search articles in wx
  17. :return:
  18. """
  19. url = "http://8.217.190.241:8888/crawler/wei_xin/keyword"
  20. payload = json.dumps({
  21. "keyword": title,
  22. "cursor": "1"
  23. })
  24. headers = {
  25. 'Content-Type': 'application/json'
  26. }
  27. response = requests.request("POST", url, headers=headers, data=payload)
  28. return response.json()
  29. @classmethod
  30. @retryOnNone()
  31. def get_article_text(cls, content_link):
  32. """
  33. 获取文章
  34. :param content_link:
  35. :return:
  36. """
  37. url = "http://8.217.190.241:8888/crawler/wei_xin/detail"
  38. payload = json.dumps({
  39. "content_link": content_link,
  40. "is_count": False,
  41. "is_ad": False
  42. })
  43. headers = {
  44. 'Content-Type': 'application/json'
  45. }
  46. response = requests.request("POST", url, headers=headers, data=payload)
  47. return response.json()
  48. @classmethod
  49. @retryOnNone()
  50. def update_msg_list(cls, ghId, index):
  51. """
  52. :return:
  53. """
  54. url = 'http://8.217.190.241:8888/crawler/wei_xin/blogger'
  55. payload = {
  56. 'account_id': ghId,
  57. 'cursor': index,
  58. }
  59. print(payload)
  60. headers = {
  61. 'Content-Type': 'application/json'
  62. }
  63. response = requests.post(url, headers=headers, data=json.dumps(payload))
  64. return response.json()
  65. @classmethod
  66. @retryOnNone()
  67. def get_account_by_url(cls, content_url):
  68. """
  69. 通过文章获取账号信息
  70. :param content_url:
  71. :return:
  72. """
  73. response = requests.request(
  74. "POST",
  75. url='http://8.217.190.241:8888/crawler/wei_xin/account_info',
  76. headers={'Content-Type': 'application/json'},
  77. json={"content_link": content_url}
  78. )
  79. return response.json()