【发布时间】:2016-05-02 19:27:49
【问题描述】:
我一直在尝试生成一个脚本来从网站https://services.aamc.org/msar/home#null 中抓取数据。我生成了一个 python scrapy 2.7 脚本来从网站上获取一段文本(我现在的目标是任何东西),但似乎无法让它工作。我怀疑这是因为我没有正确配置我的正则表达式来识别我试图从中刮取的跨度标签。有谁知道我可能做错了什么以及如何解决它?
非常感谢。
马特
import urllib
import re
url = "https://services.aamc.org/msar/home#null"
htmlfile = urllib.urlopen(url)
htmltext = htmlfile.read()
regex = '<td colspan="2" class="schoolLocation">(.+?)</td>'
pattern = re.compile(regex)
price = re.findall(pattern, htmltext)
print "the school location is ",price
【问题讨论】:
-
你真的在使用 Scrapy 网页抓取框架吗?
-
您可以使用
scrapy shell测试您的爬虫,另外考虑使用BeautifulSoup。 -
@Jan 我认为这个问题是错误的,看起来 OP 没有使用 Scrapy 或 BeautifulSoup。
标签: regex python-2.7 scrapy