我正在学习BeautifulSoup,并尝试从thisQuora页面上获取不同问题的链接。在
当我向下滚动网页时,网页中出现的问题不断出现并显示出来。在
当我试着用下面的代码来获取这些问题的链接时,我只得到了5个链接。ie-我只得到5个问题的链接,即使有很多问题在网站上。在
有没有什么解决办法可以让网页中出现的问题链接尽可能多?在
from bs4 import BeautifulSoup
import requests
root = 'https://www.quora.com/topic/Graduate-Record-Examination-GRE-1'
headers = {'User-Agent' : 'Mozilla/5.0 (Macintosh; Intel Mac OS X x.y; rv:42.0) Gecko/20100101 Firefox/42.' }
r = requests.get(root,headers=headers)
soup = BeautifulSoup(r.text,'html.parser')
q = soup.find('div',{'class':'paged_list_wrapper'})
no=0
for i in q.find_all('div',{'class':'story_title_container'}):
t=i.a['href']
no=no+1
print(root+t,'\n\n')
你所要达到的目标是无法用请求和美化团队来完成的。你需要用硒。 这里我用硒和铬来给出答案。Download chromedriver for you chrome version并安装selenium
pip install -U selenium
如果您使用的是windows-
executable_path='/path/to/chromedriver.exe'
更改此变量
no_of_pagedowns = 5
以指定要向下滚动的次数。在我得到以下输出
相关问题 更多 >
编程相关推荐