在python中从另一个字符串中搜索字符串

在python中从另一个字符串中搜索字符串,python,web-scraping,Python,Web Scraping,我试图从下面的字符串中提取信息,如价格、所有者、名称等 str='invokeUrl("viewphonenumber","trackCode=Property_for_Rent_View_Phone_BVersion&isPhoto=N&pid=29563627&code=&price=Rs. 29,000&bedroom=2&area=2000 sqft&verified=&possession_status=Immediate

我试图从下面的字符串中提取信息,如价格、所有者、名称等

str='invokeUrl("viewphonenumber","trackCode=Property_for_Rent_View_Phone_BVersion&isPhoto=N&pid=29563627&code=&price=Rs. 29,000&bedroom=2&area=2000 sqft&verified=&possession_status=Immediately&prop_number=1&offer=&owner=Agent&locality=Kadubeesanahalli&city=Bangalore&propertyType=Flat&categoryDesc=Rent&name=Manjunath&brEx=Y&js=true&page=result&from=search&call=N&pageOption=B&isSimilarProperty=N&moisd=50&cardType=card_Rent_O&isNight=true&isNri=false&isVisibleProperty=N<Id=86581&propertyTypeId=10002&cityId=3327&priceNumeric=29000&vph=Y","29563627");createCookie("contactTrackCookieData","Y","10");_gaq.push([ "_trackEvent", "propertySRP", "contactopen","view_card_Rent_O" ]);'
#print(str.split('&'))

str='invokeUrl(“viewphonenumber”,"trackCode=Property\u for\u Rent\u View\u Phone\u version&isPhoto=N&pid=29563627&code=&price=Rs.29000&doomy=2&area=2000平方英尺&verified=&conduction\u status=installent&prop\u number=1&offer=&owner=Agent&locality=Kadubeesanahalli&city=Bangalore&propertyType=Flat&categoryDesc=Rent&name=Manjunath&brEx=Y&js=true&page=result&from=N&pageOption=B&isSimilarProperty=N&moisd=50&cardType=card\u Rent\u O&isNight=true&isNri=false&isVisibleProperty=N首先,将字符串重命名为
s
,而不是
str
,因为后者会覆盖内置的
str()
函数

因此,由于这个问题的一般性质,您可以采取许多不同的方法。就我个人而言,我会使用
regex
提取第二个
字符串(其中包含您想要的值),然后使用
理解的混合物来形成一个
字典

使用
s=您的“str”

d
表示为:

{'moisd': '50', 'isNight': 'true', 'owner': 'Agent', 'js': 'true', 'page': 'result', 'isPhoto': 'N', 'trackCode': 'Property_for_Rent_View_Phone_BVersion', 'price': 'Rs. 29,000', 'cardType': 'card_Rent_O', 'isNri': 'false', 'cityId': '3327', 'pid': '29563627', 'pageOption': 'B', 'verified': '', 'bedroom': '2', 'offer': '', 'priceNumeric': '29000', 'city': 'Bangalore', 'prop_number': '1', 'categoryDesc': 'Rent', 'possession_status': 'Immediately', 'propertyType': 'Flat', 'from': 'search', 'isVisibleProperty': 'N<Id=86581', 'locality': 'Kadubeesanahalli', 'call': 'N', 'isSimilarProperty': 'N', 'area': '2000 sqft', 'code': '', 'vph': 'Y', 'brEx': 'Y', 'name': 'Manjunath', 'propertyTypeId': '10002'}

我使用的是Python3。我是python新手,因此无法找到实现这一点的方法。
{'moisd': '50', 'isNight': 'true', 'owner': 'Agent', 'js': 'true', 'page': 'result', 'isPhoto': 'N', 'trackCode': 'Property_for_Rent_View_Phone_BVersion', 'price': 'Rs. 29,000', 'cardType': 'card_Rent_O', 'isNri': 'false', 'cityId': '3327', 'pid': '29563627', 'pageOption': 'B', 'verified': '', 'bedroom': '2', 'offer': '', 'priceNumeric': '29000', 'city': 'Bangalore', 'prop_number': '1', 'categoryDesc': 'Rent', 'possession_status': 'Immediately', 'propertyType': 'Flat', 'from': 'search', 'isVisibleProperty': 'N<Id=86581', 'locality': 'Kadubeesanahalli', 'call': 'N', 'isSimilarProperty': 'N', 'area': '2000 sqft', 'code': '', 'vph': 'Y', 'brEx': 'Y', 'name': 'Manjunath', 'propertyTypeId': '10002'}
>>> d['price']
'Rs. 29,000'