簡體   English   中英

當使用請求和beautifulsoup加載更多內容時,我無法抓取下一頁上url不會更改的網站

[英]I can't scrape a website where url not change on its next page when load more using requests and beautifulsoup

Python Beatifulsoup 請求

import requests
import re
import os
import csv
from bs4 import BeautifulSoup





for d in searche:
    truelink = d.replace(" ","-")
    truelinkk=('https://www.fb.com

    r = requests.get(truelinkk,headers=headers).text
    soup=BeautifulSoup(r,'lxml')
    mobile=soup.find_all('li',class_='EIR5N')
 

我是python的初學者。 當使用請求和beautifulsoup 加載更多內容時,我無法抓取網址在下一頁上不會更改的網站,請有人訪問該網站讓我知道使用beautifulsoup 和請求抓取上述網站的程序。 任何答案將不勝感激謝謝請查看此鏈接https://www.olx.in/hyderabad_g4058526/q-Note-9-max-pro?isSearchCall=true

您可以在無頭模式下使用 selenium 而不是requests Eventho selenium 用於網絡自動化,它可以在這種情況下為您提供幫助。

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

begin = time.time()

options = Options()
options.headless = True
options.add_argument('--log-level=3')
driver = webdriver.Chrome(options=options)

由於 URL 不會更改,因此您必須通過獲取其 xpath 並單擊所需的按鈕:

driver.find_element_by_xpath('xpath code').click()

您可以避免使用請求,您可以使用以下方法獲取頁面的源代碼:

html_text = driver.page_source
soup = BeautifulSoup(html_text, 'lxml')

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM