Reputation: 4291
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?
Upvotes: 1
Views: 149
Reputation: 52665
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
Upvotes: 1
Reputation: 26
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)?
Upvotes: 1