python - 无法在python中使用BeautifulSoup提取whatsapp号

标签 python regex beautifulsoup

我是python的新手,我正在提取一些数据。我想使用正则表达式提取whatsapp数字。

这是我的代码:

from textwrap import shorten
from bs4 import BeautifulSoup
import json
import requests
import re

url = 'https://m.propertyfinder.ae/en/rent/apartment-for-rent-dubai-dubai-marina-marina-promenade-delphine-tower-7276805.html'
response = requests.get(url)
soup = BeautifulSoup(response.text, 'lxml')

whatsapp = re.match('{"type":"whatsapp","value":"([^"]+)"[^}]+}', soup)

print(whatsapp)




我收到如下错误:


Traceback (most recent call last):
  File "/Users/evilslab/Documents/Websites/www.futurepoint.dev.cc/dobuyme/python/fetchFinder.py", line 11, in <module>
    whatsapp = re.match('{"type":"whatsapp","value":"([^"]+)"[^}]+}', soup)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/re.py", line 189, in match
    return _compile(pattern, flags).match(string)
TypeError: expected string or bytes-like object


我如何从源数据中提取whatsapp号?

最佳答案

您可以像这样获得比赛:

address.group()                                                                                                                                                                                  
# 'Organization","name":"Gold 


我希望这有帮助

关于python - 无法在python中使用BeautifulSoup提取whatsapp号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59386897/

相关文章:

python - 如何获取 BeautifulSoup 中搜索的上下文?

python - 网页抓取 : getting KeyError when parsing JSON in Python

python - 尝试使用 Google 搜索搜索图片,错误 400

python lxml xpath : how to get this predicate working

regex - 将句号和空格后的所有字母大写

python - 使用带有注释更改的 matplotlib 的交互式条形图

regex - sed:替换多行

regex - 获取IP地址的前3段

python - 为什么不立即更新 Frame 的自然高度?

Python SocketServer不会握手