一部、特にwidgetidを解析したいURLがあります。
<a href="http://www.somesite.com/process.asp?widgetid=4530">Widgets Rock!</a>
私はこのPythonを書きました(私はPythonの初心者です-バージョンは2.7です):
import re
from bs4 import BeautifulSoup
doc = open('c:\Python27\some_xml_file.txt')
soup = BeautifulSoup(doc)
links = soup.findAll('a')
# debugging statements
print type(links[7])
# output: <class 'bs4.element.Tag'>
print links[7]
# output: <a href="http://www.somesite.com/process.asp?widgetid=4530">Widgets Rock!</a>
theURL = links[7].attrs['href']
print theURL
# output: http://www.somesite.com/process.asp?widgetid=4530
print type(theURL)
# output: <type 'unicode'>
is_widget_url = re.compile('[0-9]')
print is_widget_url.match(theURL)
# output: None (I know this isn't the correct regex but I'd think it
# would match if there's any number in there!)
正規表現 (または正規表現の使用方法の理解) に何かが欠けていると思いますが、それを理解できません。
ご協力いただきありがとうございます!