每个星期五,使用crontab,我想把opetable.com刮掉1000磅。预订2个星期天的未来。页面的URL是提交的结果。
html = urlopen('http://www.opentable.com/s/PopRestaurantList?covers=2¤tview=list&datetime=2016-03-06+19%3A00&metroid=15&onlypoptimes=true&personalizer=true&ref=2213&showmap=false&size=100&sort=Popularity')
使用urlparse或其他模块;和datetime如何更改URL以始终具有从刮刀运行起9天后的日期。
bsObj = BeautifulSoup(html.read().decode('utf-8'),"lxml")
table = bsObj.findAll("div", {"class":"content-section-list infinite-results-list"})
headlines = table[0].findAll("a", {"class":"rest-row-name rest-name"})
for headline in headlines:
restaurant = (headline.get_text().encode('utf-8'))
print(restaurant)
print '\n'
我将日期时间增量设置为9天
date = datetime.datetime.today()
date += datetime.timedelta(days=9)
print(date)
答案 0 :(得分:0)
您可以使用字符串格式和date.strftime来执行此操作:
date = datetime.datetime.today()
date += datetime.timedelta(days=9)
url = 'http://www.opentable.com/s/PopRestaurantList?covers=2¤tview=list&datetime={date}+19%3A00&metroid=15&onlypoptimes=true&personalizer=true&ref=2213&showmap=false&size=100&sort=Popularity'
html = urlopen(url.format(date=date.strftime('%Y-%m-%d')))