简体   繁体   中英

Cannot get data using requests.get

I want to get the name of a stock from a web page.

I sent the query using requsts

data = requests.get(r'http://www.etnet.com.hk/www/eng/stocks/realtime/quote.php?code=5').text

In normal situation, 'data' should contain 'HSBC HOLDINGS' but it does not.

'HSBC HOLDINGS' in data # False

What's wrong with my code?

How to solve the problem?

This should work

'HSBC HOLDINGS' in data.text

Edit: I did not see you already used '.text' in the first line. For me your code returns true. What is your return, when you print(data)?

Try to add referer header to get required output:

data = requests.get(r'http://www.etnet.com.hk/www/eng/stocks/realtime/quote.php?code=5', headers={'referer': 'http://www.etnet.com.hk/www/eng/stocks/realtime/quote.php?code=00005'}).text
'HSBC HOLDINGS' in data
# True

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM