【发布时间】:2018-08-19 07:48:42
【问题描述】:
我正在使用 CSS 选择器通过 beautifulsoup 4 模块从网络上抓取数据。
查看示例代码:
# pull website
res = requests.get('https://dailystoic.com/epictetus/')
#parse file
soup = bs4.BeautifulSoup(res.text, 'html.parser')
# CSS selector
elems = soup.select('body > div.wrap.container > div > main > article > div.entry-content > p:nth-child(1) > em > a:nth-child(3)')
# take content and store in variable
content = elems[0].text.strip()
# print content
print(content)
我想要来自超链接的 html 文本。我不想要 URL,而是超链接所说的内容。
【问题讨论】:
标签: python html css beautifulsoup