wxSpiderApi.py 2.1 KB

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