python - 如何用 Python 编写一个简单的蜘蛛?

标签 python web-crawler scrapy

几周来我一直在尝试编写这个蜘蛛,但没有成功。我用 Python 编写此代码的最佳方式是什么:

1) 初始网址:http://www.whitecase.com/Attorneys/List.aspx?LastName=A

2) 从初始 url 使用此正则表达式获取这些 url:

hxs.select('//td[@class="altRow"][1]/a/@href').re('/.a\w+')

[u'/cabel', u'/jacevedo', u'/jacuna', u'/aadler', u'/zahmedani', u'/tairisto', u
/zalbert', u'/salberts', u'/aaleksandrova', u'/malhadeff', u'/nalivojvodic', u'
....

3) 转到每个 url 并使用此正则表达式抓取学校信息

hxs.select('//td[@class="mainColumnTDa"]').re('(?<=(JD,\s))(.*?)(\d+)'

[u'JD, ', u'University of Florida Levin College of Law, <em>magna cum laude</em> , Order of the Coif, Symposium Editor, Florida Law Review, Awards for highest grades in Comparative Constitutional History, Legal Drafting, Real Property and Sales, ', u'2007']

4) 将抓取的学校信息写入schools.csv文件

你能帮我用 Python 写这个蜘蛛吗?我一直在尝试用 Scrapy 编写它,但没有成功。看我之前的question .

谢谢。

最佳答案

http://www.ibm.com/developerworks/linux/library/l-spider/具有良好描述的 IBM 文章

http://code.activestate.com/recipes/576551/ Python 食谱,更好的代码但更少的解释

关于python - 如何用 Python 编写一个简单的蜘蛛?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1805231/

相关文章:

javascript - Python Flask-Sockets 无法在蓝图中工作

python - Selenium 远程网络驱动程序错误

search - 如何在 OpenSearchServer 中抓取但不索引网页?

javascript - 获取脚本标签内的内容

python - 如何从 Ruby 调用 Python 代码?

python - 简单的python循环问题

python - 为什么 pandas reindex() 不就地运行?

Java正则表达式解析/robots.txt

python - 如何通过外部脚本用scrapy获取爬虫返回数据?

python - Scrapy:在方法之间传递项目