【发布时间】:2017-02-15 18:08:04
【问题描述】:
# 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]
在变量'value'内的文本内
我该怎么做?
根据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)
仍然出现错误
Traceback(最近一次调用最后一次): 文件“ex1.py”,第 19 行,在 my_match = re.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:预期的字符串或类似字节的对象
【问题讨论】: