【问题标题】:Sending Requests in Python Returns None When Trying to Scrape a Specific Web page尝试抓取特定网页时,在 Python 中发送请求返回无
【发布时间】:2020-03-29 03:38:15
【问题描述】:
shoe = input('Shoe name: ')

URL = 'https://stockx.com/search?s='+shoe

page = requests.get(URL, headers= headers)

soup = BeautifulSoup(page.content, 'html.parser')

time.sleep(2) #this was to ensure the webpage was having enough time to load so that it wouldn't try to scrape a prematurely loaded website. 

test = soup.find(class_ = 'BrowseSearchDescription__SearchConfirmation-sc-1mt8qyd-1 dcjzxm')

print(test) #returns none
print(URL) #prings the URL (which is the correct URL of the website I'm attempting to scrape)

我知道我可以使用 Selenium 轻松完成此操作,但是,它会加载 chrome 选项卡并导航到网页,因此效率非常低。我正在努力提高效率,而我最初的“原型”确实使用了 Selenium,但是它总是被检测为机器人,并且我的整个代码都被验证码阻止了。我是否做错了什么导致代码返回“无”,或者该特定网页是否不可抓取。如果需要,具体网址为https://stockx.com/search?s=yeezy

【问题讨论】:

  • 如果不是安全问题,你能提供标题吗?

标签: python html python-requests


【解决方案1】:

我试过你的代码,结果如下。

代码

shoe = 'yeezy'
URL = 'https://stockx.com/search?s='+shoe
page = requests.get(URL)
soup = bs.BeautifulSoup(page.content, 'html.parser')

当我看到soup 中的内容时,结果如下。

结果

..
..

<div id="px-captcha">
</div>
<p> Access to this page has been denied because 
    we believe you are using automation tools to browse the website.</p>

..
..

是的,我猜开发人员不希望网站被抓取

【讨论】:

    猜你喜欢
    • 2019-04-15
    • 2022-01-18
    • 2018-03-22
    • 2016-02-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-01
    • 2015-06-24
    相关资源
    最近更新 更多