admin管理员组文章数量:1415484
I'm trying to intercept the response from the web server and extract the body. it uses the module nodriver
to successfully load the page and capture the request event. However when it attempts to send the get_response_body generator to the tab (body = await self.tab.send(gen)
) it gets stuck. What am i missing?
import nodriver
import asyncio
import os
url = "=%0A%7B%0A%20%20products(%0A%20%20%20%20filter%3A%20%7B%0A%20%20%20%20%20%20%0A%20%20%20%20%20%20sku%3A%20%7B%20in%3A%20%5B%2222817%22%5D%20%7D%2C%0A%20%20%20%20%20%20%0A%20%20%20%20%20%20%0A%20%20%20%20%20%20%7D%0A%20%20%20%20pageSize%3A%208%2C%0A%20%20%20%20sort%3A%20%7Bposition%3A%20ASC%7D%0A%20%20%20%20)%20%7B%0A%20%20%20%20items%20%7B%0A%20%20%20%20%20%20%20%20related_products%20%7B%0A%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20sku%0A%20%20%20%20%20%20id%0A%20%20%20%20%20%20name%0A%20%20%20%20%20%20small_image%20%7B%0A%20%20%20%20%20%20%20%20label%0A%20%20%20%20%20%20%20%20url%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20thumbnail%20%7B%0A%20%20%20%20%20%20%20%20url%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20url_key%0A%20%20%20%20%20%20url_suffix%0A%20%20%20%20%20%20visibility%0A%20%20%20%20%20%20status%0A%20%20%20%20%20%20price_range%20%7B%0A%20%20%20%20%20%20%20%20minimum_price%20%7B%0A%20%20%20%20%20%20%20%20%20%20regular_price%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20value%0A%20%20%20%20%20%20%20%20%20%20%20%20currency%0A%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20final_price%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20value%0A%20%20%20%20%20%20%20%20%20%20%20%20currency%0A%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D"
class Scraper:
tab: nodriver.Tab
def __init__(self):
nodriver.loop().run_until_complete(self.main())
async def handle_request(self, event):
print(f"Event: {event}")
request_id = event.request_id
print(f"Request ID: {request_id}")
gen = nodriver.cdpwork.get_response_body(request_id)
print(f"Generator: {gen}")
if event.request.url == url:
print("Probably about to get stuck...")
body = await self.tab.send(gen) # Gets stuck here
print(f"Body: {body}")
async def main(self):
browser = await nodriver.start()
self.tab = browser.main_tab
await self.tab.send(nodriver.cdpwork.enable())
self.tab.add_handler(nodriver.cdpwork.RequestWillBeSent, self.handle_request)
await self.tab.get(url)
await self.tab.wait(t=10)
if __name__ == "__main__":
Scraper()
本文标签: pythonNodriver web scraping program gets stuck at cdpnetworkgetresponsebodyStack Overflow
版权声明:本文标题:python - Nodriver web scraping program gets stuck at cdp.network.get_response_body? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745162577a2645505.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论