【发布时间】:2018-12-18 12:31:01
【问题描述】:
我想从 Quora 中抓取与某些特定主题相关的问题,该主题有超过 4 个答案左右。
我想找到
a) 答案数
b) 与每个问题相关的标签
这是我的程序:
res=requests.get("https://www.quora.com/How-does-Quora-automatically-know-what-tags-to-put-for-a-question")
soup=BeautifulSoup(res.text, 'lxml')
# All the ans inside pagedlist_item
ans=soup.find_all('div', {'class' : 'pagedlist_item'})
#Question Name inside question_text_edit
qname=soup.find('div', {'class' : 'question_text_edit'})
#qnam=soup.find('div', {'class' : 'question_text_edit'})
#Tag of Question
tags=soup.find('div', {'class' : 'QuestionTopicHorizontalList TopicList'})
#checking to see if "TV" is the tag of the question in the current webpage
#Also, checking if no. of answers of the given question >=4, if yes then print the question
#logic for checking the conditions
no_ans=0;
if "TV" in tags.text:
print(i.text)
for a in ans:
no_ans=no_ans+1
if no_ans>=4:
print(qname.text)
我想搜索许多带有标签TV的此类页面,然后对这些页面执行检查以满足上述条件。
检查条件的逻辑出现在代码的末尾。但是,这仅适用于地址在requests.get("") 函数内的网页中的一个问题。
如何让代码自动迭代多个带有“TV”标签的网页(多个问题),而不是将单个网页地址传递给requests.get("") 函数?
另外,我想收集多个问题(多达 40 个左右)。
【问题讨论】:
-
先看看
curl -
是的,你也可以开始看看 BeautifulSoup
-
@AjaySinghNegi 该方法正如我所描述的那样:找出您(人类)会手动执行的操作以获取所有这些页面的列表,然后自动化构建该列表的过程。例如,如果您作为人类必须单击 Quora 文章上的 [TV] 标签以获取有关电视的所有 Quora 问题的列表,那么您现在知道您必须构建一个机器人来为您单击该标签.对我来说似乎很简单,而且我不知道您在这里寻求帮助的原因是什么。无论您作为一个人会手动执行此操作,都将其自动化。
-
@AjaySinghNegi 你不需要框架。只写代码。这个问题没有什么特别之处。这是日常编程。这主要是程序所做的事情,它们最初是为了什么而编写的:自动执行否则人类必须做的任务。
-
@DanBron 先生,感谢您的帮助。我希望现在回答这个问题可以帮助我消除“您已达到问题限制”。
标签: python web-scraping quora