【发布时间】:2017-08-31 14:03:19
【问题描述】:
我正在尝试从“https://www.pakwheels.com/forums/c/travel-n-tours”中提取“Saudi Sim Card”等所有链接。我正在使用 Selenium 网络驱动程序来滚动网页,但我无法提取所有链接。我得到的错误是“None 类型的对象没有 href 属性”有什么建议吗?
from PageScroller import WebPageScroller
import bs4 as bs
sourceUrl='https://www.pakwheels.com/forums/c/travel-n-tours'
#----------------------- Scrolling to the bottom of page and getting source code --------------------------------------#
scrollObject=WebPageScroller
pageSource=scrollObject.getScrolledPageSource(scrollObject,sourceUrl)
# ------------------------------------- Getting links ---------------------------------- #
soup = bs.BeautifulSoup(pageSource, 'lxml')
blogUrls=[]
for url in soup.find_all('a'):
if((url.get('href').find('/forums/t/')!=-1) and (url.get('href').find('about-the-travel-n-tours-category')==-1) and (url.get('href').find('/forums/t/topic/')==-1)):
blogUrls.append(url.get('href'))
print(url.get('href'))
print(len(blogUrls))
【问题讨论】:
-
本网站通过发布代码、显示结果和提出特定问题来工作。
-
我编辑了这个问题。现在更清楚了吗?
-
我还没有直接上传图片的权限。我只能将图像添加为链接。怎样才能获得这个特权?
标签: python selenium-webdriver web-scraping