I want to drop the snippet of the date displayed in Google search results into csv.

Asked 2 years ago, Updated 2 years ago, 77 views

I'm a Python beginner.
As the title suggests, I would like to print a snippet of the date displayed in Google search results to csv.

https://arakan-pgm-ai.hatenablog.com/entry/2018/01/17/080000
When I copied the code of the above site, I was able to get the title, link, etc., but I can't get the date information well because I don't know how to view the CSS selector.

Could someone tell me the code to output the date to csv as well?

python web-scraping

2022-09-30 21:35

2 Answers


in the CSS selector .s>.st
represents the st class, which is a child element of the s class.
Furthermore, if it is class f of the child element,
.s>.st>.f
will be


2022-09-30 21:35

Simply soup.select('span.f') gives you date information, but it also contains other information, and you cannot match titles and links.

The date can be found in the Search Results Description section, so the code for the site in the question can be found in the Get Search Results Description section below.

# Get search results title and link
link_elem01 = group.select('.r>a')
# Get Description of Search Results
link_elem02 = group.select('.s>.st')

TITLE If you want to match a link, you must retrieve the date information from link_elem02[i] in a loop using the variable i later in the code.

If you are not sure how to view the CSS selector, the date is at the beginning of link_elem02, so try to retrieve the first few characters (depending on the configuration) whether you search for strings or use regular expressions.


2022-09-30 21:35

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.