search.py 803 B

1234567891011121314151617181920212223242526272829
  1. import json
  2. from applications.utils import AsyncHttpClient
  3. async def search_in_toutiao(keyword):
  4. url = "http://crawler-cn.aiddit.com/crawler/tou_tiao_hao/keyword"
  5. data = {
  6. "keyword": keyword,
  7. }
  8. headers = {
  9. "Content-Type": "application/json",
  10. }
  11. async with AsyncHttpClient(timeout=120) as client:
  12. response = await client.post(url, json=data, headers=headers)
  13. return response
  14. async def get_toutiao_detail(link):
  15. url = "http://crawler-cn.aiddit.com/crawler/tou_tiao_hao/detail"
  16. data = {
  17. "content_link": link,
  18. }
  19. headers = {
  20. "Content-Type": "application/json",
  21. }
  22. async with AsyncHttpClient(timeout=120) as client:
  23. response = await client.post(url, json=data, headers=headers)
  24. return response