0

I am trying to scrap specific information from the site but I am receiving an error. Here is the simplified version of the main problem:

import re

b='href="/bp/vendor?vendorCodes=C901U">C901U</a></span></div></div></div><div heyaa'

c=re.search('href="/bp/vendor?vendorCodes=C901U">C901U</a></span></div></div></div><div',b)

If I try to find what is in c I receive this error:

c.group()

Traceback (most recent call last):
  File "<pyshell#87>", line 1, in <module>
    c.group()
AttributeError: 'NoneType' object has no attribute 'group'

Thanks in advance.

wjandrea
  • 28,235
  • 9
  • 60
  • 81
Areff
  • 11
  • 2
  • 2
    `?` is a special character in regex. Escape it: `\?`. – wjandrea Aug 31 '22 at 14:06
  • 4
    In general, don't use regular expressions to parse HTML at all; use an HTML parser. – chepner Aug 31 '22 at 14:09
  • 1
    BTW, welcome to Stack Overflow! Please take the [tour] and read [ask] for tips like how to write a good title and start with your own research. I'm voting to close this question because the solution is trivial: either you forgot `?` is special or you weren't aware because you aren't familiar enough with regex. If it's the latter, you could maybe check out the official Python [Regular Expression HOWTO](https://docs.python.org/3/howto/regex.html). – wjandrea Aug 31 '22 at 14:11
  • Does this answer your question? "[Regex Matching Error](/q/1268761/90527)", "[RegEx match open tags except XHTML self-contained tags](/a/1732454/90527)", "[regex add questionmark as a character \[duplicate\]](/q/31951614/90527)" – outis Sep 01 '22 at 10:07

0 Answers0