Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Welcome to Software Development on Codidact!

Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.

Post History

66%
+2 −0
Q&A Python BeautifulSoup how to correctly parse quote symbols in link titles (broken html)?

I'm learning some basic web scraping so I can download part of a static website for offline viewing. In the process, I'm running into link tags that look something like this: <a href='https://e...

1 answer  ·  posted 11mo ago by pycoder‭  ·  last activity 11mo ago by ArtOfCode‭

Question python python-3 beautifulsoup
#1: Initial revision by user avatar pycoder‭ · 2025-10-17T16:29:42Z (11 months ago)
Python BeautifulSoup how to correctly parse quote symbols in link titles (broken html)?
I'm learning some basic web scraping so I can download part of a static website for offline viewing. In the process, I'm running into link tags that look something like this:

```
<a href='https://example.com' title='Example web author's link to another page'>Page X</a>
```

Or, that's what I'd expect to get when looking at the page source. When I run `html = urlopen(url).read()` and then `soup = BeautifulSoup(html, 'lxml')`, BeautifulSoup somehow mangles the link title so it ends up looking more like this, depending on the text and number of quotes:

```
<a href="https://example.com" s'=" link to another page" title="Example web author">Page X</a>
<a page'="" href="https://example.com" s="" title="Author">Page X</a>
```

I'm certain the odd number of quote symbols is throwing the thing off by making it think the title ends earlier than it really does. It's a bit of a problem since `link.get('title')` only returns the part of the title before any quote symbols. Changing the parser didn't work and search engines are only giving me generic BeautifulSoup articles when I look this up, so I've no idea how to fix it. I'm running BeautifulSoup version 4.14.2 on Arch Linux if that helps.