一
原链接:用Python爬虫爬取链家网上的房源信息_shayebuhui_a的博客-CSDN博客_python爬取链家
打开链家网页:https://sh.lianjia.com/zufang/ :用F12以页面中元素进行检查,点击左上角的小箭头,得到相关信息。在这个页面可以通过将鼠标悬浮在相关信息上,可以得到其源代码
我们可以发现网页中包含浦东-川沙-园西小区的源代码为:
<a target="_blank" href="/https/blog.csdn.net/zufang/pudong/">浦东</a>
<a href="/https/blog.csdn.net/zufang/jinqiao/" target="_blank">川沙</a>
<a title="园西小区" href="/https/blog.csdn.net/zufang/c5011000007323/" target="_blank">园西小区</a>
使用正则表达式获取网页信息的语句可以写为:
#区域
findplace1 = re.compile(r'<a href="/https/blog.csdn.net/zufang/.*" target="_blank">(.*)</a>-<a href="/https/blog.csdn.net/zufang/.* target="_blank">.*</a>-<a href="/https/blog.csdn.net/zufang.*" target="_blank" title=".*">.*</a>') #创建正则表达式对象,表示规则(字符串的模式)
findplace2= re.compile(r'<a href="/https/blog.csdn.net/zufang/.*" target="_blank">.*</a>-<a href="/https/blog.csdn.net/zufang/.* target="_blank">(.*)</a>-<a href="/https/blog.csdn.net/zufang.*" target="_blank" title=".*">.*</a>')
findplace3 = re.compile(r'<a href="/https/blog.csdn.net/zufang/.*" target="_blank">.*</a>-<a href="/https/blog.csdn.net/zufang/.* target="_blank">.*</a>-<a h