https://www.size.co.uk/featured/footwear/に移動してコンテンツをスクラブするスクリプトを作成したいのですが、スクリプトを実行するとアクセスが拒否されました。ここでは、コードは次のようになります。スクレイピング中にアクセスが拒否された
from urllib import urlopen
from bs4 import BeautifulSoup as BS
url = urlopen('https://www.size.co.uk/')
print BS(url, 'lxml')
出力は
<html><head>
<title>Access Denied</title>
</head><body>
<h1>Access Denied</h1>
You don't have permission to access "http://www.size.co.uk/" on this server.
<p>
Reference #18.6202655f.1498945327.11002828
</p></body>
</html>
私は他のウェブサイトでそれをしようとすると、コードが正常に動作しても、私はセレンを使用する場合、何も起こりませんが、私はまだ方法を知りたいですSeleniumを使用せずにこのエラーを回避します。私は、同じアクセス拒否エラーを得たhttp://www.footpatrol.co.uk/shopのように別のウェブサイト上でセレンを使用する場合でも、ここでfootpatrolのコードは次のとおりです。
from selenium import webdriver
driver = webdriver.PhantomJS('C:\Users\V\Desktop\PY\web_scrape\phantomjs.exe')
driver.get('http://www.footpatrol.com')
pageSource = driver.page_source
soup = BS(pageSource, 'lxml')
print soup
出力は次のとおりです。
にユーザーエージェントヘッダーを設定し<html><head>
<title>Access Denied</title>
</head><body>
<h1>Access Denied</h1>
You don't have permission to access "http://www.footpatrol.co.uk/" on this
server.<p>
Reference #18.6202655f.1498945644.110590db
</p></body></html>
ブラウザのように見える。 –
@Alenあなたはセレンを使用することを意味しますか? –
あなたは何のpythonですか? –