Repository navigation
Closed
Labels
P3Performance, refactor, docs or testsbugSomething isn't workingcorrectnessProduces wrong output or wrong behaviour
Description
Expected: A page that answers 301 gives an event. If the design is to give none, the documentation says so.
Actual: The seed links /a, /b and /c. /a and /b answer 301 to /c. The server receives requests for /a and /b, but the stream has events only for / and /c.
Minimal input: Seed / with links to /a, /b and /c. max_depth=1. The script reads crawl_stream and prints each event.
The maintainer can intend this behaviour. A caller that counts requests against events sees a gap.
Reproduce
The script reads each event with json.loads(repr(ev)), because repr of a CrawlEvent gives its JSON form.
Install:
pip install crawlberg==1.11.1
Save as cb10.py:
"""A page that answers 301 gives no crawl event."""
import asyncio, json, threading
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
import crawlberg
REQ = []
class H(BaseHTTPRequestHandler):
def do_GET(self):
REQ.append(self.path)
if self.path in ("/a", "/b"):
self.send_response(301); self.send_header("Location", "/c"); self.send_header("Content-Length", "0"); self.end_headers(); return
if self.path == "/":
body = "<html><body><a href='/a'>a</a> <a href='/b'>b</a> <a href='/c'>c</a></body></html>"
else:
body = "<html><body><p>Page C text.</p></body></html>"
data = body.encode()
self.send_response(200); self.send_header("Content-Type", "text/html"); self.send_header("Content-Length", str(len(data))); self.end_headers(); self.wfile.write(data)
def log_message(self, *a):
pass
server = ThreadingHTTPServer(("127.0.0.1", 0), H)
threading.Thread(target=server.serve_forever, daemon=True).start()
port = server.server_address[1]
async def main():
config = crawlberg.CrawlConfig(
max_depth=1, max_pages=10, respect_robots_txt=False,
ssrf=crawlberg.SsrfPolicy(deny_private=False),
browser=crawlberg.BrowserConfig(mode="never"))
stream = crawlberg.crawl_stream(crawlberg.create_engine(config), f"http://127.0.0.1:{port}/")
async for ev in stream:
data = json.loads(repr(ev)) # the event prints as JSON
if data["type"] == "page":
r = data["result"]
print("event page", r["url"], r["status_code"], len(r["markdown"]["content"]))
else:
print("event", data)
print("server requests:", sorted(set(REQ)))
asyncio.run(main())Run:
python cb10.py
Actual output
event page http://127.0.0.1:35599/ 200 90
event page http://127.0.0.1:35599/c 200 13
event {'pages_crawled': 2, 'type': 'complete'}
server requests: ['/', '/a', '/b', '/c']
Metadata
Metadata
Assignees
Labels
P3Performance, refactor, docs or testsbugSomething isn't workingcorrectnessProduces wrong output or wrong behaviour
Activity
fix(crawl): error-page bodies under soft_http_errors; redirect-to-404…