我基本上是从特定页面抓取数据。我有这个代码:
regex = '<ul class="w462">(.*?)</ul>'
opener.open(baseurl)
urllib2.install_opener(opener)
... rest of code omitted ...
requestData = urllib2.urlopen(request)
htmlText = requestData.read()
pattern = re.compile(regex)
movies = re.findall(pattern, htmlText)
# Lines below will always returns empty.
if not movies:
print "List is empty. Printing source instead...", "\n\n"
print htmlText
else:
print movies
htmlText的内容:
<ul class="w462">
... bunch of <li>s (the content i want to retrieve).
</ul>
htmlText 包含正确的来源(我尝试按 ctrl+F 并且我可以验证它是否包含所需的 ul 元素。只是我的正则表达式无法获得所需的内容。
我试图改用这个:
movies = re.findall(r'<ul class="w462">(.*?)</ul>', htmlText)
有谁知道出了什么问题?