从日期动态URL python mySQL中删除表

从日期动态URL python mySQL中删除表,python,mysql,datetime,beautifulsoup,Python,Mysql,Datetime,Beautifulsoup,我可以为特定日期的URL刮取目标值。。。我应该如何设置datetime和scraping来跳过没有目标表的URL??这是我目前掌握的代码-- 我知道我在{date}中加入了URL以获得动态工作的日期-如果URL为空,则提供一个静态URL date_time = urlopen(url.format(date=date.strftime('%Y%m%d'))) address = url print 'Retrieving information from: ' + address pri

我可以为特定日期的URL刮取目标值。。。我应该如何设置datetime和scraping来跳过没有目标表的URL??这是我目前掌握的代码--

我知道我在{date}中加入了URL以获得动态工作的日期-如果URL为空,则提供一个静态URL

date_time = urlopen(url.format(date=date.strftime('%Y%m%d')))
address = url
print 'Retrieving information from: ' + address    
print '\n'
soup = BeautifulSoup (requests.get(address).content, "lxml")
刮除过程如下:

rows = soup.select('div#column0 table tr')[2:]

headers = ['name', 'last', 'chg', 'pct_chg',
       'total_money_flow', 'total_tick_up', 'total_tick_down', 'total_up_down_ratio',
       'block_money_flow', 'block_tick_up', 'block_tick_down', 'block_up_down_ratio']
for row in rows:
# skip non-data rows
    if row.find("td", class_="b14") is True:
    continue

print(dict(zip(headers, [cell.get_text(strip=True) for cell in row.find_all('td')])))

你不能使用
尝试
跳过没有目标表的日期吗?我想是的,但是这些值是如何得到一个脚本来获取追溯日期的呢?我知道它是不是像URL.x那样的数字。我可以使用n=1;对于我在(1,n+1)范围内但不知道如何从我的头顶上明智地操作它datetime,你可以用日期创建一个单独的文件并将其作为列表读取,然后在该列表上迭代,或者使用
timedelta
你不能使用
try
跳过没有目标表的日期吗?我想是的,但是这些值是如何得到一个脚本来获取追溯日期的呢?我知道它是否是像URL.x这样的数字。我可以使用n=1;对于在(1,n+1)范围内但不确定如何在我的头顶上操作datetime的i,您可以用日期创建一个单独的文件并将其作为列表读取,然后在该列表上迭代,或者使用
timedelta
rows = soup.select('div#column0 table tr')[2:]

headers = ['name', 'last', 'chg', 'pct_chg',
       'total_money_flow', 'total_tick_up', 'total_tick_down', 'total_up_down_ratio',
       'block_money_flow', 'block_tick_up', 'block_tick_down', 'block_up_down_ratio']
for row in rows:
# skip non-data rows
    if row.find("td", class_="b14") is True:
    continue

print(dict(zip(headers, [cell.get_text(strip=True) for cell in row.find_all('td')])))