我已阅读使用此命令网址:删除 r n开始刮
import urllib2
from bs4 import BeautifulSoup
req = urllib2.Request(url, headers=hdr)
req2 = urllib2.urlopen(req)
content = req2.read()
soup = BeautifulSoup(content, "lxml")
我想刮与结构的网站象下面这样:
<div class='\"companyNameWrapper\"'>
\r\n
<div class='\"companyName\"'>
ACP Holding Deutschland GmbH
</div>
\r\n
问题是因为斜杠,命令如
soup.findAll("div", {"class":"companyName"}):
不起作用。我需要将汤转换为str以使用.replace('\',''),但这种类型是字符串和soup.findAll(和类似的bs4命令无效)。
有没有人有建议?
感谢
我看到**正则表达式**并立即想到:https://stackoverflow.com/a/1732454/4022608。使用BS的正则表达式处理程序是好的,但:) – Baldrickk