How to make a request to website and download search data - python-3.x

I'm trying to download some car VIN data for a list of individuals. This involves making a request to a website "http://vin.place/search.php" via requests.get in python3.7.
My code looks like this:
import requests
import pandas as pd
from bs4 import BeautifulSoup
payload = {'first name':'JOHN','last name':'DOE'}
webpage_response = requests.get("http://vin.place/search.php",data = payload)
webpage = webpage_response.content
soup = BeautifulSoup(webpage,"html.parser")
results = soup.select(".search-content")
for x in results:
print(x.get_text())
Unfortunately, I am finding that results = [] instead. I suspect there is something wrong with the way that I am coding up the requests.get command. I am not sure how what the right keys should be for the website. Can anyone please help? Thanks.

The payload you have is wrong, it should be first, last. And the names in lowercase:
import requests
from bs4 import BeautifulSoup
payload = {'first':'john','last':'doe'}
webpage_response = requests.post("http://vin.place/search.php", data=payload)
webpage = webpage_response.content
soup = BeautifulSoup(webpage,"html.parser")
results = soup.select(".search-content")
for x in results:
print(x.text)
Prints:
JOHN DOE Purchase of a 2007 HONDA ACCORD
JOHN DOE Purchase of a 2007 CHRYSLER TOWN AND COUNTRY
JOHN DOE Purchase of a 2007 DODGE RAM PICKUP 2500
JOHN DOE Purchase of a 2007 DODGE RAM PICKUP 1500
JOHN DOE Purchase of a 2007 VOLKSWAGEN PASSAT
JOHN DOE Purchase of a 2007 VOLKSWAGEN JETTA
JOHN DOE Purchase of a 2007 CHRYSLER SEBRING
JOHN DOE Purchase of a 2007 DODGE RAM PICKUP 1500
JOHN DOE Purchase of a 2007 JEEP PATRIOT
JOHN DOE Purchase of a 2007 Chevrolet TrailBlazer
JOHN DOE Purchase of a 2007 FORD EDGE
JOHN DOE Purchase of a 2007 JEEP WRANGLER UNLIMITED
JOHN DOE Purchase of a 2007 DODGE RAM PICKUP 2500
JOHN DOE Purchase of a 2007 FORD MUSTANG
JOHN DOE Purchase of a 2007 JEEP WRANGLER
JOHN DOE Purchase of a 2007 CHRYSLER 300
JOHN DOE Purchase of a 2007 JEEP WRANGLER UNLIMITED
JOHN DOE Purchase of a 2007 DODGE MAGNUM
JOHN DOE Purchase of a 2007 CADILLAC ESCALADE ESV
JOHN DOE Purchase of a 2007 FORD F-150
JOHN DOE Purchase of a 2007 HONDA ACCORD
JOHN DOE Purchase of a 2007 JEEP LIBERTY
JOHN DOE Purchase of a 2007 CADILLAC ESCALADE
JOHN DOE Purchase of a 2007 DODGE RAM PICKUP 1500
JOHN DOE Purchase of a 2007 JEEP WRANGLER

looking at the form data as sent by chrome when performing the search manually, the data is: first=JOHN&last=DOE, also, the site uses POST
please try this:
import requests
import pandas as pd
from bs4 import BeautifulSoup
payload = {'first':'JOHN','last':'DOE'}
webpage_response = requests.post("http://vin.place/search.php",data = payload)
webpage = webpage_response.content
soup = BeautifulSoup(webpage,"html.parser")
results = soup.select(".search-content")
for x in results:
print(x.get_text())

Related

How update a dataframe column value from second dataframe where values on two specific columns that can repeat on first match on both dataframes?

I have two dataframes with different information about a person, on the first dataframe, person's name may repeat in different rows. I want to add/update the first dataframe with data from the second dataframe where the two columns containing person's data matches on both. Here an example on what I need to accomplish:
df1:
name surname
0 john doe
1 mary doe
2 peter someone
3 mary doe
4 john another
5 paul another
df2:
name surname account_id
0 peter someone 100
1 john doe 200
2 mary doe 300
3 john another 400
I need to accomplish this:
df1:
name surname account_id
0 john doe 200
1 mary doe 300
2 peter someone 100
3 mary doe 300
4 john another 400
5 paul another <empty>
Thanks!

Excel cell lookup in subtotaled range

I'd like to use index/match to lookup values in a subtotaled range. Using the sample data below, from another sheet (Sheet 2), I need to lookup the total NY Company hours for each employee.
Sheet 2:
| Bob | NY Company | ???? |
This formula returns the first match of NY Company Total
=INDEX('Sheet1!A1:C45,MATCH(Sheet2!B2 & " Total",'Sheet1!B1:B45,0),3)
Now I need to expand the lookup to include the Employee (Bob). Also, Column A is blank on the total Row. I've started to work with something like the following but no luck.
=INDEX('Sheet1!A1:C45,MATCH(1,('Sheet2!B2 & " Total"='Sheet1!B1:B45)*('Sheet2!B1='Sheet1!A1:A45)),3)
Also, as the sample data below looks perfect in the preview and then looks really bad after saving, I've added a pic with the sample data.
Sample data:
Sample Data:
A
B
C
Employee
Customer
Hours
Bob
ABC Company
5
Bob
ABC Company
3
ABC Company Total
8
Bob
NY Company
7
Bob
NY Company
7
Bob
NY Company
5
Bob
NY Company
3
NY Company Total
22
Bob
Jet Company
1
Jet Company Total
1
Carrie
ABC Company
1
Carrie
ABC Company
4
ABC Company Total
5
Carrie
NY Company
6
Carrie
NY Company
2
Carrie
NY Company
3
NY Company Total
11
Carrie
Jet Company
7
Carrie
Jet Company
9
Jet Company Total
16
Carrie
XYZ Company
4
XYZ Company Total
4
Gale
Cats Service
2
Gale
Cats Service
6
Gale
Cats Service
1
Cats Service Total
9
Gale
NY Company
6
Gale
NY Company
8
NY Company Total
14
Gale
XYZ Company
1
XYZ Company Total
1
John
NY Company
3
John
NY Company
5
NY Company Total
8
John
XYZ Company
8
John
XYZ Company
5
XYZ Company Total
13
Ken
ABC Company
10
ABC Company Total
10
Ken
NY Company
2
Ken
NY Company
3
Ken
NY Company
5
NY Company Total
10
Grand Total
132
Any suggestions??

How do I re-create a family mailing list from a contact list created in Excel?

My wife has been assembling a mailing list in Excel for Christmas cards with columns
for names & address. I decided to expand the list to include emails and phone numbers
but this then 'breaks' her original design as the original 'family'-oriented rows are
now people-oriented ones spread across multiple rows but sharing the same mailing address.
Original list:
Smith Bob & Jane 123 Main St Stockton CA
Jones Dave & Sue 456 Adams Rd Carmel CA
turned into:
Smith Bob 123 Main St Stockton CA bsmith#hotmail.com (444) 123-2342
Smith Jane 123 Main St Stockton CA jsmith#hotmail.com (444) 345-4565
Jones Dave 456 Adams Rd Carmel CA djones#aol.com (415) 453-3454
Jones Sue 456 Adams Rd Carmel CA sjones#aol.com (512) 234-3433
What is the best way to keep my wife happy by reconstituting her original mailing list
every November? I'm presuming a macro that uses addresses as unique key, copies
them to a new sheet and then pulls in the names? Is this considered a 'view' in Excel
parlance? An initial skeleton would be most helpful, VB isn't my forte.
I'm inclined to suggest a code-less way first. An easy way would be to add a type column and an index column, and give your entries a "salutation" record, e.g.:
S 1 Bob & Jane Smith 123 Main St Stockton CA
F 1 Smith Bob 123 Main St Stockton CA bsmith#hotmail.com (444) 123-2342
F 1 Smith Jane 123 Main St Stockton CA jsmith#hotmail.com (444) 345-4565
S 8 The Jones Family 456 Adams Rd Carmel CA
F 8 Jones Dave 456 Adams Rd Carmel CA djones#aol.com (415) 453-3454
F 8 Jones Sue 456 Adams Rd Carmel CA sjones#aol.com (512) 234-3433
S 9 The Other Joneses ...
With this layout, you could use filters to sort and select data.

ms excel turn columns into rows

I am looking for a way to take an excel spread sheet and change the columns to rows. The sheet is currently designed like this.
Employee Name Expiration 1 Expiration 2 Expiration 3 Expiration 4
John Doe
Jane Doe
What I need to do is convert it to this
Employee Name Expiration Date
John Doe 1 12-12-12
John Doe 2 12-12-12
John Doe 3 12-12-12
John Doe 4 12-12-12
Jane Doe 1 12-1-12
Jane Doe 2 12-1-12
Jane Doe 3 12-1-12
Jane Doe 4 12-1-12
I am not even sure if this is possible.
You can do this very simply with an INDEX(MATCH(),MATCH()) formula.
This screenshot should be enough to get you started:
Screenshot(1)
Let me know if you need any more info.

Conditionally assign unique values

I have data, for example:
John Doe MD 1
Ben Doe PA
Cal Doe MD 1
Drum Doe PA
Egg Doe NP
Fun Doe MD 1
So everywhere there's an MD I have an IF condition assigning the number 1. But I want to isolate and pull all the names with a 1 consecutively. Example:
John Doe
Cal Doe
Fun Doe
I know I just have to have numeric values such as: john doe-1, cal doe-2, fun doe-3.
I'm having problem with the logic if someone can help I'll appreciate it.
If your data is in three columns (starting A2) then maybe:
=IF(B2="MD",MAX(C$1:C1)+1,"")

Resources