【发布时间】:2021-05-02 09:20:14
【问题描述】:
因此,为了提高我的抓取技巧,我一直在尝试下载 https://ikeacatalogues.ikea.com/sv-1950/page/1 中的文档,但是当我尝试获取带或不带 id 的 div 时,我得到的只是 <div id="fakescroll"</div> 和我想要的是指向存在于锚标记中的文档的直接链接
我也无法访问它。我厌倦了找到网页中存在的所有链接,它返回一个空列表。
请帮忙。这是我的代码。此代码返回空输出:
from bs4 import BeautifulSoup
from selenium import webdriver
url = "https://ikeacatalogues.ikea.com/sv-1950/page/1"
browser = webdriver.Chrome(executable_path="/path/to/chromedriver.exe")
browser.get(url)
soup = BeautifulSoup(browser.page_source,"html.parser")
items=soup.select(""div", {"id": "main_menu"}")
print(items)
这是我获取所有 href 的代码。输出为空。
import httplib2
from bs4 import BeautifulSoup, SoupStrainer
http = httplib2.Http()
status, response = http.request('https://ikeacatalogues.ikea.com/sv-1950/page/1')
for link in BeautifulSoup(response, parse_only=SoupStrainer('a')):
if link.has_attr('href'):
print(link['href'])
【问题讨论】:
标签: python web-scraping beautifulsoup