Skip to content

Instantly share code, notes, and snippets.

@5teven1in
Created August 3, 2020 18:07
Show Gist options
  • Save 5teven1in/4d748607171d0645e16848d1a0aa46f8 to your computer and use it in GitHub Desktop.
Save 5teven1in/4d748607171d0645e16848d1a0aa46f8 to your computer and use it in GitHub Desktop.
import json
import httpx
from bs4 import BeautifulSoup as BS
from urllib.parse import quote, unquote
search_url = "https://shopee.tw/search?keyword={}"
search_items_url = "https://shopee.tw/api/v2/search_items/?by=relevancy&keyword={}&limit=50&newest=0&order=desc&page_type=search&version=2"
def get_items(keyword):
headers = {"Referer": search_url.format(keyword)}
res = httpx.get(search_items_url.format(keyword), headers=headers)
return json.loads(res.text)
def main():
keyword = "襪子"
output = get_items(quote(keyword))
print(json.dumps(output))
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment