Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from seleniumwire.utils import decode as decodesw
- from seleniumwire import webdriver
- from urllib.parse import unquote
- import json
- def show_requests_url(driver,target_url):
- driver.get(target_url)
- urls = []
- for request in driver.requests:
- urls.append({"url":request.url})
- return urls
- def show_responses(driver, target_url):
- driver.get(target_url)
- responses = []
- for request in driver.requests:
- try:
- data = decodesw(
- request.response.body,
- request.response.headers.get('Content-Encoding', 'identity')
- )
- resp = json.loads(data.decode("utf-8"))
- responses.append(resp)
- except:
- pass
- return responses
- def main():
- keywords = ['https://www.google-analytics.com']
- # uncomment this if you want full responses
- # options = webdriver.FirefoxOptions()
- options = webdriver.ChromeOptions()
- options.add_argument("--headless")
- driver = webdriver.Chrome(seleniumwire_options={"disable_encoding":True},options=options)
- target_url = "https://pergikuliner.com/restaurants?page=1"
- # target_url = "https://www.google.com"
- urls = show_requests_url(driver,target_url)
- responses = show_responses(driver,target_url)
- for url in urls:
- for kw in keywords:
- if kw in url['url']:
- print(unquote(url['url']))
- with open('json_responses.json','w') as fo:
- json.dump(responses,fo)
- driver.close()
- if __name__ == "__main__":
- main()
Advertisement
Comments
-
- Firefox is able to capture more responses for some reasons
- example:
- [
- {
- "country_code": "US",
- "country_name": "United States"
- },
- {
- "metadata": {},
- "timestamp": 1702426203007,
- "changes": [
- {
- "id": "3ddbe540-6900-30ef-7853-199a3b4bc6df",
- "last_modified": 1702072014351,
- "bucket": "main",
- "collection": "quicksuggest",
- "host": "firefox.settings.services.mozilla.com"
- }
- ]
- },
- {
- "metadata": {
- "schema": {
- "type": "object",
- "properties": {
- "id": {
- "type": "string"
- }
- }
- },
- "signature": {
- "ref": "20uju743097rl2aarsb7lrgodj",
- "x5u": "https://content-signature-2.cdn.mozilla.net/chains/remote-settings.content-signature.mozilla.org-2024-01-19-16-42-21.chain",
- Chrome response:
- [{}, {"place": [{"city": "jakarta", "places": ["Green Ville", "Kebon Jeruk", "Kedoya", "Jelambar", "Daan Mogot", "Kemanggisan", "Mangga Besar", "Tanjung Duren", "Bendungan Hilir", "Gatot Subroto", "Cempaka Putih", "Cikini", "Salemba", "Menteng", "Gajah Mada", "Gambir", "Blok M", "Melawai", "Kebayoran Baru", "Cilan
Add Comment
Please, Sign In to add comment
Advertisement