Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python网页垃圾处理会导致块_Python_Web Scraping_Beautifulsoup_Proxy_Selenium Chromedriver - Fatal编程技术网

python网页垃圾处理会导致块

python网页垃圾处理会导致块,python,web-scraping,beautifulsoup,proxy,selenium-chromedriver,Python,Web Scraping,Beautifulsoup,Proxy,Selenium Chromedriver,我想浏览德国房地产网站immobilienscout24.de。它不是为了商业用途或出版,我也不打算滥发该网站,它只是为了编码实践。我想编写一个python工具,自动下载给定immobilienscout24.de站点的HTML。我曾尝试使用beautifulsoup,但是,解析后的HTML不会显示内容,而是询问我是否是机器人等,这意味着我的webscraper被检测到并被阻止(我可以在Firefox中访问该网站)。我已经设置了一个referer、一个delay和一个随机用户代理。我还能做些什么

我想浏览德国房地产网站immobilienscout24.de。它不是为了商业用途或出版,我也不打算滥发该网站,它只是为了编码实践。我想编写一个python工具,自动下载给定immobilienscout24.de站点的HTML。我曾尝试使用beautifulsoup,但是,解析后的HTML不会显示内容,而是询问我是否是机器人等,这意味着我的webscraper被检测到并被阻止(我可以在Firefox中访问该网站)。我已经设置了一个referer、一个delay和一个随机用户代理。我还能做些什么来避免被检测到(即旋转代理、随机点击、无头chrome、其他未被检测到的网页垃圾工具…)? 我在网上找到的东西可能是导致该区块的原因:

  • 缺少/错误的cookies
  • 缺少javascript支持/其他javascript问题
  • 无鼠标点击/移动
  • 标题不完整/不真实
  • SSL/TLS指纹和其他让我难以理解的东西
如果有人有一个工作的解决方案,可以刮网站,比如说,10次而不被阻止,我会非常感谢。以下是我目前的代码:

from bs4 import BeautifulSoup
import numpy
import time
from fake_useragent import UserAgent

def get_html(url, headers): #scrapes and parses the HTML of a given URL while using custom header
    r = requests.get(url, headers=headers)
    soup = BeautifulSoup(r.text, 'html.parser')
    return soup

ua = UserAgent()
headers = {
    "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9", 
    "Accept-Encoding": "gzip, deflate", 
    "Accept-Language": "de,de-DE;q=0.8,en;q=0.6", 
    "Dnt": "1", 
    "Host": "https://www.immobilienscout24.de/", 
    "Upgrade-Insecure-Requests": "1", 
    "User-Agent": ua.random, 
  }
delays = [3, 5, 7, 4, 4, 11]
time.sleep(numpy.random.choice(delays))
test = get_html("https://www.immobilienscout24.de/Suche/de/baden-wuerttemberg/heidelberg/wohnung-kaufen?enteredFrom=one_step_search", headers)```

这段代码还需要更多的工作,但我猜导入请求不起作用,因为它需要运行js代码,但如果您使用类似于selenium的东西,它应该会起作用,因为它可以运行js代码。此外,request_html有Puppeter类似于selenium


from requests_html import HTMLSession
import re
#from fake_useragent import UserAgent
#create the session
#ua = UserAgent()
session = HTMLSession()

#define our URL
url = 'https://www.immobilienscout24.de/Suche/de/baden-wuerttemberg/heidelberg/wohnung-kaufen'

#use the session to get the data
r = session.get(url)

#Render the page, up the number on scrolldown to page down multiple times on a page
r.html.render(sleep=1,timeout = 30, keep_page=True, scrolldown=1)
r.html.page.screenshot({'C:/Users/program/Desktop/help': 'example.png'})

print(r.text)
session.close()


非常感谢。不幸的是,我运行了它,但仍然会导致阻塞:(