Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/blackberry/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用python bs4基于标题的屏幕抓取_Python_Web Scraping_Beautifulsoup - Fatal编程技术网

使用python bs4基于标题的屏幕抓取

使用python bs4基于标题的屏幕抓取,python,web-scraping,beautifulsoup,Python,Web Scraping,Beautifulsoup,我在使用bs4进行屏幕抓取时遇到问题。下面是我的代码 from bs4 import BeautifulSoup import urllib2 url="http://www.99acres.com/property-in-velachery-chennai-south-ffid?" page=urllib2.urlopen(url) soup = BeautifulSoup(page.read()) properties=soup.findAll('a',{'title':'Bedroom'}

我在使用bs4进行屏幕抓取时遇到问题。下面是我的代码

from bs4 import BeautifulSoup
import urllib2
url="http://www.99acres.com/property-in-velachery-chennai-south-ffid?"
page=urllib2.urlopen(url)
soup = BeautifulSoup(page.read())
properties=soup.findAll('a',{'title':'Bedroom'})
for eachproperty in properties:
    print eachproperty['href']+",", eachproperty.string
当我分析网站时,实际的标题结构如下

1间卧室,位于Velachery的住宅公寓
,用于所有锚链。但是我没有得到任何输出,也没有错误。那么,我该如何告诉程序清除所有标题中包含单词
“卧房”
的数据呢


希望我说得很清楚。

您需要在此处使用正则表达式,因为您只希望匹配那些在标题中包含
卧房
的锚链接,而不是整个标题:

import re

properties = soup.find_all('a', title=re.compile('Bedroom'))
这为您给定的URL提供了47个匹配项