我使用python selenium来做网页抓取。我想抓取有特定日期的网站(如[01-20])和有特定文字的标题(如'public'),代码如何能满足这两点?
I tried the following but no luck
提前感谢你!!!。
href:
<td width="89%" height="26">
<a href="hrefhref" target="_blank" title="sth sth public">sth sth public</a>
<td width="8%" align="center">[01-20]</td>
code:
titles = driver.find_elements_by_css_selector("[title*='public']")
for title in titles:
links=[title.get_attribute('href') for title in driver.find_elements_by_xpath("//td[text()='[01-20]']/preceding::td[1]/a")]
urls = [links.get_attribute("href") for links in driver.find_elements_by_css_selector("[title*='public']")]
for url in urls:
print(url)
driver.get(url)
###do something