我有一个 html 文件,如下所示:
<form action="/2811457/follow?gsid=3_5bce9b871484d3af90c89f37" method="post">
<div>
<a href="/2811457/follow?page=2&gsid=3_5bce9b871484d3af90c89f37">next_page</a>
<input name="mp" type="hidden" value="3" />
<input type="text" name="page" size="2" style='-wap-input-format: "*N"' />
<input type="submit" value="jump" /> 1/3
</div>
</form>
如何从文件中提取“1/3”?
它是html的一部分,我打算说清楚。当我使用beautifulsoup时,
我是beautifulsoup的新手,我看过文档,但仍然很困惑。
如何从 html 文件中提取“1/3”?
total_urls_num = re.findall('\d+/\d+',response)
工作代码:
from BeautifulSoup import BeautifulSoup
import re
with open("html.txt","r") as f:
response = f.read()
print response
soup = BeautifulSoup(response)
delete_urls = soup.findAll('a', href=re.compile('follow\?page')) #works,should escape ?
print delete_urls
#total_urls_num = re.findall('\d+/\d+',response)
total_urls_num = soup.find('input',type='submit')
print total_urls_num