【发布时间】:2013-11-10 07:22:44
【问题描述】:
我正在尝试使用 BeautifulSoup 在网站中进行一些网络爬取。但是当我尝试获取 div 类 AddressInfo 中的内容时出现错误,这是我要抓取的网站的一部分:
<h4>Altônia</h4>
<div class="addressInfo">
Rua Getulio Vargas, 1201<br>
Centro - Iporã - PR<br>
87550-000<br>
<br>
(44) 3659-2721<br>
<a href="mailto:altoniacentro.pr@escolas.com.br">altoniacentro.pr@escolas.com.br</a><br>
</div>
这是我的代码:
from urllib import urlopen
from BeautifulSoup import BeautifulSoup
import re
# Copy all of the content from the provided web page
webpage = urlopen('site url....').read()
# Grab everything that lies between the h4 tags using a REGEX
patFinderTitle = re.compile('<h4>(.*)</h4>')
# Grab everything that lies between the class addressInfo tags using a REGEX
patFinderAddress = re.compile('<div class="addressInfo">(.*)</div>') **<- get error here**
这是我得到的错误:
raise ValueError('Cannot process flags argument with a compiled pattern') ValueError: Cannot process flags argument with a compiled模式
我该如何解决这个问题?
【问题讨论】:
-
既然可以使用 BeautifulSoup 进行解析,为什么还要使用正则表达式?此外,请粘贴您的所有代码。您粘贴的代码看起来不完整,并且不会在此表单中产生错误。
标签: python regex python-2.7 beautifulsoup