我想从网站上抓取数据,但首先我想获取带有分页的页面。这里我使用python作为程序语言,并且我已经得到了这段代码。但是当我运行它时,它不能正常工作。当 response.url 与 expected_url 不匹配时,必须停止结果。有人知道如何解决吗?请帮忙,谢谢。这是代码:
from bs4 import BeautifulSoup
import urllib.request
count = 0
url = "http://www.belanjamimo.net/foundation-bb-cream/?o=a&s=%d"
def get_url(url):
req = urllib.request.Request(url)
return urllib.request.urlopen(req)
expected_url = url % count
response = get_url(expected_url)
while (response.url == expected_url):
print("GET {0}".format(expected_url))
count += 9
expected_url = url % count
response = get_url(expected_url)
相关分类