Created
August 3, 2020 18:07
-
-
Save 5teven1in/4d748607171d0645e16848d1a0aa46f8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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