【发布时间】:2019-05-30 19:27:38
【问题描述】:
我在 python 中编写了一个脚本来获取网站上不同帖子的不同链接。如果我选择像a[href^='/questions/'] 或.question-hyperlink 这样的任何单个属性,我可以获得所需的输出。
我的问题是:我如何在
.select()方法中使用来自同一节点的两个属性,就像我在下面尝试过的那样?
到目前为止我的尝试(没有结果;也没有错误):
import requests
from bs4 import BeautifulSoup
link = "https://stackoverflow.com/questions/tagged/web-scraping"
res = requests.get(link)
soup = BeautifulSoup(res.text,'lxml')
for item in soup.select("a[href^='/questions/'].question-hyperlink"):
print(item.get("href"))
【问题讨论】:
标签: python python-3.x web-scraping beautifulsoup css-selectors