# Ex1
# Number of datasets currently listed on data.gov
# http://catalog.data.gov/dataset
import requests
import re
from bs4 import BeautifulSoup
page = requests.get(
"http://catalog.data.gov/dataset")
soup = BeautifulSoup(page.content, 'html.parser')
value = soup.find_all(class_='new-results')
results = re.search([0-9][0-9][0-9],[0-9][0-9][0-9], value
print(value)
代码就在上面..我想在regex = [0-9] [0-9] [0-9],[ 0-9] [0-9] [0-9]寻找python变量里面的正则表达式文本
变量 '值'
我怎么能做到这一点内的文本里面?
基于ShellayLee的建议我改成了
import requests
import re
from bs4 import BeautifulSoup
page = requests.get(
"http://catalog.data.gov/dataset")
soup = BeautifulSoup(page.content, 'html.parser')
value = soup.find_all(class_='new-results')
my_match = re.search(r'\d\d\d,\d\d\d', value)
print(my_match)
仍然得到错误
回溯(最近最后一次通话): 文件 “ex1.py” 19行,在 my_match =重.search(r'\ d \ d \ d,\ d \ d \ d',值) 文件“/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/re.py”,行182,搜索 return _compile(pattern,flags).search(string) TypeError:期望的字符串或类似字节的对象
谢谢ShellayLee! –
@BinuAlexander如果你发现答案有帮助,请给我一个upvote :) – ShellayLee