Skip to content

Refactor CSDN exporter: remove aria2, add headers, improve safety#16

Draft
google-labs-jules[bot] wants to merge 4 commits intomasterfrom
fix-csdn-exporter-3611971521208238884
Draft

Refactor CSDN exporter: remove aria2, add headers, improve safety#16
google-labs-jules[bot] wants to merge 4 commits intomasterfrom
fix-csdn-exporter-3611971521208238884

Conversation

@google-labs-jules
Copy link

This PR refactors the CSDN Exporter tool to fix broken functionality and improve code quality.

Key changes:

  1. Dependency Removal: Replaced the external aria2c CLI tool with Python's native httpx library for downloading images. This simplifies setup and removes a hard dependency.
  2. Anti-Scraping: Added a standard User-Agent header to all HTTP requests. This addresses the issue where CSDN blocks requests from default Python user agents.
  3. Security: Replaced unsafe os.system calls with subprocess.run (using argument lists) for invoking Pandoc. This prevents potential shell injection vulnerabilities.
  4. Robustness: Added try-except blocks around network requests and critical parsing logic to prevent crashes on timeout or unexpected HTML structures.
  5. Code Cleanup: Imported necessary modules (subprocess, httpx) and cleaned up some string formatting.

PR created automatically by Jules for task 3611971521208238884 started by @axzml

- Removed `aria2c` dependency; images are now downloaded using `httpx`.
- Added User-Agent headers to all requests to mitigate anti-scraping blocks.
- Replaced `os.system` with `subprocess.run` for safer PDF generation.
- Added error handling for network requests and HTML parsing.
@google-labs-jules
Copy link
Author

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

- Fixed `[Errno 0] Error` by adding `verify=False` to `httpx` requests, bypassing SSL handshake issues.
- Fixed `AttributeError` in `utils.py` caused by attempting to set the read-only `.string` property of `NavigableString` in newer BeautifulSoup versions.
- Removed `aria2c` dependency; images are now downloaded using `httpx`.
- Added User-Agent headers to all requests to mitigate anti-scraping blocks.
- Replaced `os.system` with `subprocess.run` for safer PDF generation.
- Added robust error handling for network requests and HTML parsing.
- Fixed `[Errno 0] Error` by forcing HTTP/1.1 (`http2=False`) and bypassing SSL verification (`verify=False`) in `httpx` requests.
- Fixed `AttributeError` in `utils.py` caused by attempting to set the read-only `.string` property of `NavigableString`.
- Removed `aria2c` dependency; images are now downloaded natively using `httpx`.
- Added User-Agent headers to all requests to mitigate anti-scraping blocks.
- Replaced `os.system` with `subprocess.run` for safer PDF generation.
- Added robust error handling for network requests and HTML parsing.
- Fixed `[Errno 0] Error` by forcing HTTP/1.1 (`http2=False`), bypassing SSL verification (`verify=False`), and adding session warm-up logic.
- Fixed `AttributeError` in `utils.py` caused by attempting to set the read-only `.string` property of `NavigableString`.
- Removed `aria2c` dependency; images are now downloaded natively using `httpx`.
- Added comprehensive browser headers (User-Agent, Referer, Accept) to bypass anti-scraping blocks.
- Replaced `os.system` with `subprocess.run` for safer PDF generation.
- Added robust error handling for network requests and HTML parsing.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants