在网页抓取和更改日期格式时移动到下一页
url\u list是一个url列表,其中一个 http://www.moneycontrol.com/company-article/cadilahealthcare/news/CHC#CHC 我发现,要移动到不同的年份和不同的页面,有一个href代码,但我似乎不能使用它。下面是从第1页提取链接的代码。我想在所有可用的年份和页面上都这么做。你知道吗
另外,当我从html中提取日期时,它的格式是 [上次更新时间:2019年2月7日下午03:05 IST |来源:Moneycontrol.com] 我要的是mm/dd/yy格式的日期,我怎样才能做到呢?你知道吗
for urls in url_list:
html = requests.get(urls)
soup = BeautifulSoup(html.text,'html.parser') # Create a BeautifulSoup object
# Retrieve a list of all the links and the titles for the respective links
#word1,word2,word3 = "US","USA","USFDA"
sub_links = soup.find_all('a', class_='arial11_summ')
for links in sub_links:
sp = BeautifulSoup(str(links),'html.parser') # first convert into a string
tag = sp.a
#if word1 in tag['title'] or word2 in tag['title'] or word3 in tag['title']:
category_links = Base_url + tag["href"]
List_of_links.append(category_links)
time.sleep(3)
我想做的是先删除第一页,然后移到下一页,以此类推,在删除某一年的可用页之后,代码将移到下一年。请解释一下我该怎么做。你知道吗
移到下一页:
像这样将param添加到URL https://www.moneycontrol.com/stocks/company_info/stock_news.php?sc_id=CHC&durationType=Y&Year=2018年
对于年份列表,您可以从第1页获得
提取date:sub字符串以仅获取datetime,然后像这样解析时间和时区
我使用pytz更新了设置时区
相关问题 更多 >
编程相关推荐