def GenContent(address,what):
return urllib.urlopen("http://www.yelp.com/search?find_desc="+what+"&#find_loc="+address).read()
I am using python to do this.
It works prefectly in my browser.
def GenContent(address,what):
return urllib.urlopen("http://www.yelp.com/search?find_desc="+what+"&#find_loc="+address).read()
I am using python to do this.
It works prefectly in my browser.
The 400 you saw almost always means the request URL or headers were malformed, not that the page “works in a browser” and not for your script. The first post shows the string &#find_loc= in the built URL — that is a red flag. A literal # starts a fragment (never sent to the server) and HTML-escaped entities (&) can end up inside the URL string if you build it from HTML text. Also unencoded spaces or non‑ASCII characters in what or address will break the request.
Practical, reliable fixes:
& (not #). import requests
r = requests.get("https://www.yelp.com/search",
params={'find_desc': what, 'find_loc': address},
headers={'User-Agent': 'Mozilla/5.0'},
timeout=10)
html = r.text r.url with requests) and try that exact URL in your browser to reproduce the error. That shows whether the server actually sees the malformed string.User-Agent and follow redirects; some servers reject requests that look like bots. If you still get 400, check for embedded HTML entities in your inputs or extremely long queries.Notes and cautions:
Quick checklist: remove any # fragments, percent‑encode parameters, verify the exact URL your code sends, and send a normal browser User-Agent.
Jump to Post— Gribouillis 1,391What is your question ?
Jump to Post— chriswelborn 63What was the original problem? Your method reminds me of Visual Basic's "SendKey()". If downloading and writing an html page to disk was the problem, it can be easily solved in python.
I posted this in two fourms, python and webdev
What is your question ?
Is there a way to make it not be like this?
It works perfectly in my browser.
I did it the hard way, I used this:
import win32api
import win32con
import win32com
import ctypes
import webbrowser
import time
import os
import shutil
SendInput = ctypes.windll.user32.SendInput
# C struct redefinitions
PUL = ctypes.POINTER(ctypes.c_ulong)
class KeyBdInput(ctypes.Structure):
_fields_ = [("wVk", ctypes.c_ushort),
("wScan", ctypes.c_ushort),
("dwFlags", ctypes.c_ulong),
("time", ctypes.c_ulong),
("dwExtraInfo", PUL)]
class HardwareInput(ctypes.Structure):
_fields_ = [("uMsg", ctypes.c_ulong),
("wParamL", ctypes.c_short),
("wParamH", ctypes.c_ushort)]
class MouseInput(ctypes.Structure):
_fields_ = [("dx", ctypes.c_long),
("dy", ctypes.c_long),
("mouseData", ctypes.c_ulong),
("dwFlags", ctypes.c_ulong),
("time",ctypes.c_ulong),
("dwExtraInfo", PUL)]
class Input_I(ctypes.Union):
_fields_ = [("ki", KeyBdInput),
("mi", MouseInput),
("hi", HardwareInput)]
class Input(ctypes.Structure):
_fields_ = [("type", ctypes.c_ulong),
("ii", Input_I)]
# Actuals Functions
def PressKey(hexKeyCode):
extra = ctypes.c_ulong(0)
ii_ = Input_I()
ii_.ki = KeyBdInput( hexKeyCode, 0x48, 0, 0, ctypes.pointer(extra) )
x = Input( ctypes.c_ulong(1), ii_ )
ctypes.windll.user32.SendInput(1, ctypes.pointer(x), ctypes.sizeof(x))
def ReleaseKey(hexKeyCode):
extra = ctypes.c_ulong(0)
ii_ = Input_I()
ii_.ki = KeyBdInput( hexKeyCode, 0x48, 0x0002, 0, ctypes.pointer(extra) )
x = Input( ctypes.c_ulong(1), ii_ )
ctypes.windll.user32.SendInput(1, ctypes.pointer(x), ctypes.sizeof(x))
def PressEnter():
PressKey(0xD)
ReleaseKey(0x0D)
def GetContent(l,googlechrome=True):
webbrowser.open(l)
time.sleep(1.5)
def click(x,y):
win32api.SetCursorPos((x,y))
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,x,y,0,0)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,x,y,0,0)
def rightclick(x,y):
win32api.SetCursorPos((x,y))
win32api.mouse_event(win32con.MOUSEEVENTF_RIGHTDOWN,x,y,0,0)
win32api.mouse_event(win32con.MOUSEEVENTF_RIGHTUP,x,y,0,0)
rightclick(100,100)
time.sleep(.5)
click(220, 191)
time.sleep(2.5)
PressEnter()
time.sleep(3.5)
for i in os.listdir("C:/Users/James/Desktop/"):
if i.endswith(".htm") or i.endswith(".html"):
url = i
break
r = open(url).read()
os.remove(url)
if googlechrome:
try:
shutil.rmtree(url+"_files")
except:
pass
return r
you need pywin32
What was the original problem? Your method reminds me of Visual Basic's "SendKey()". If downloading and writing an html page to disk was the problem, it can be easily solved in python.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.