Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
236 views
in Technique[技术] by (71.8m points)

python - My kernel is stuck processing simple code (web-scraping)

I'm trying to do some pretty simple web-scraping with beautifulsoup, and I am using the requests.get command, to fetch HTML data from a website. However, from this given website, my kernel can't seem to process the request, and my kernel gets stuck. Has anyone experienced this before and found a solution?

I'm simply trying the following:

r = requests.get('http://www.nasdaqomxnordic.com/etp/leverage-certifikat/info?Instrument=CSE192562')

question from:https://stackoverflow.com/questions/65541041/my-kernel-is-stuck-processing-simple-code-web-scraping

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The problem is that, this website requires some headers to load , which you can pass in the request

as

>>>requests.get('http://www.nasdaqomxnordic.com/etp/leverage-certifikat/info?Instrument=CSE192562', headers={"User-Agent": "Mozilla/5.0 (X11; CrOS x86_64 12871.102.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.141 Safari/537.36"})
<Response [200]>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...