【发布时间】:2019-07-13 16:11:18
【问题描述】:
在网页抓取和更改日期格式时移动到下一页
url_list 是一个 url 列表,其中一个是 http://www.moneycontrol.com/company-article/cadilahealthcare/news/CHC#CHC 我发现要移动到不同的年份和不同的页面,有一个 href 代码,但我似乎无法使用它。这是从第 1 页提取链接的代码。我想在所有可用的年份和可用页面中都这样做。
当我从 html 中提取日期时,它的格式为 [最后更新时间:IST 2019 年 2 月 7 日下午 3:05 |资料来源: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)
我想要做的是抓取第一页然后移动到下一页等等,在抓取特定年份的可用页面之后,代码移动到下一年。请解释我将如何去做。
【问题讨论】:
标签: python html web-scraping beautifulsoup